

<!DOCTYPE html>
<html>

<head>
   
    
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!--360浏览器优先以webkit内核解析-->


<title>费用申请明细</title>
    <script src="__STATIC__/layout/js/jquery.min.js"></script>
<link rel="shortcut icon" href="__STATIC__/layout/favicon.ico">
<link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
<link href="__STATIC__/layout/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
<!--<link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">-->
<link href="__STATIC__/layout/css/channel.css?v=4.1.0" rel="stylesheet">
<!-- Sweet Alert -->
<link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<!--<link href="__STATIC__/layout/js/plugins/select/bootstrap-select.css" rel="stylesheet">-->
<link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
<link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
<link href="__STATIC__/xds/js/select2/css/select2.css" rel="stylesheet" />
<script src="__STATIC__/xds/js/select2/js/select2.js"></script>
<script src="__STATIC__/layout/js/jquery.cookie.js?"></script>

<script type="text/javascript">var jisuanurl="{:url('Bs/tejia')}";</script>
<script src="__STATIC__/xds/js/jisuan.js"></script>

    <style>
        .hover{
            display: block;
            width: 80px;
            line-height: 30px;
            height: 30px;
            overflow: hidden;
            position: relative;
        }
        .hover:hover{
            overflow: visible;
        }
        .hover .ex{
            position: absolute;
            left: 80px;
            top: 0;
            width: 200px;
            line-height: 60px;
            background: #ff0;
            text-align: center;
        }
    </style>

    <style>
        #form1 p{
            line-height: 20px;
            padding: 4px;
        }
        .titleImg{
            width: 20px;
            height: 20px;
            margin-right: 8px;
            display: inline-block;
            vertical-align: middle;
        }
        .table{
            margin-bottom: 10px;
        }
          .handup{
            color: #a6e1fc;
            display: inline-block;
            padding-left: 10px;
            cursor: pointer;
        }
         .btn-white.active{
            color: #fff;
            background-color: #337ab7;
        }
        .bootstrap-select{
            height: 36px;
            border-radius: 6px;
        }
        .bootstrap-select .btn-default {
             border-radius: 6px;
             background-color: #fff; 
             border-color: #c2c2c2; 
             color: #333; 
            }
        .btn-default:hover, .btn-default:focus, .btn-default:active, .btn-default.active, .open .dropdown-toggle.btn-default{
            border-radius: 6px;
             background-color: #fff; 
             border-color: #c2c2c2; 
             color: #333; 
         }
    </style>

</head>

<body class="white-bg" style="padding: 3px;font-size: 13px">
    <div class="page-heade">
       <h2 class="title_color text-center">费用申请明细</h2>
    </div>
    <form action="" class="form-inline" id="form1">
        <input type="hidden" name="tiapplyid" id="tiapplyid" {if condition="$aid neq 0"} value="{$aid}" {/if}/>
         <!--新加的-->
        <input name="zon" id="zon" value="{$title}" type="hidden"/>
        <input name="ti_id" id="ti_id" value="{$id}" type="hidden"/>
        <input name="jxs_id" value="{$jxsid}" id="jxs_ids" type="hidden"/>

        <input name="ctime" value="{$apply['ctime']}" id="ctime" type="hidden"/>

        <input name="khxqtype" id="khxqtype" value="2" type="hidden"/>
        <input name="cpxqtype" id="cpxqtype" value="{$apply['cp_type']}" type="hidden"/>
        <p><img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt=""><b>基本信息</b></p>
        <!--基本信息-->
        <table class="table table-bordered bud_hei">
            <thead>
                <tr class="info">
                    <th class="text-center">活动期间</th>
                    <th class="text-center">预算期间</th>
                    <th class="text-center">预计核销日期</th>
                    <th class="text-center">活动简述及目的</th>
                    <th class="text-center">所属专项方案</th>
                </tr>
            </thead>
            <tbody>
                <tr class="text-center">
                    <td>
                        <!--<span class="xds_addTime"  whereTime="startName:s1,endName:s2,jisuanshijiancha:#actionText,GetDateStr:#yujihexiaotime,disabled:1,rets:'活动期间必须选择',startvalue:{$apply['start']},endvalue:{$apply['end']}" >
                        </span>-->
                        <span class="xds_addTime"  whereTime="startName:s1,endName:s2,jisuanshijiancha:#actionText,GetDateStr:#yujihexiaotime,disabled:1,startvalue:{$apply['start']},endvalue:{$apply['end']}" >
                        </span>
                        <span class="text-danger"  id="actionText"></span>
                    </td>
                    <td class="xds_addTime"  whereTime="startName:start,endName:end,disabled:1,startvalue:{$apply['ysstart']},endvalue:{$apply['ysend']}" >
                    </td>
                    <td><input type="text" id="yujihexiaotime"  name="expCanTime" value="{$apply['expCanTime']}" class="form-control"></td>
                    <td><input type="text" id="hdjs" class="form-control" name="brief" value="{$apply['brief']}" style="width: 95%"></td>
                    <td>无</td>
                </tr>
            </tbody>
        </table>
        <p><img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt=""><b>费用详情</b></p>
        <table class="table table-bordered bud_hei">
            <thead>
                <tr class="info">
                    <th class="text-center">费用类型</th>
                    <th class="text-center">支付方式</th>
                    <th class="text-center">费用额（含税）</th>
                    <th class="text-center">收款方</th>
                    <th class="text-center">成本中心</th>
                    <th class="text-center">费用说明</th>
                    <th class="text-center">
                        <button class="btn btn-success " type="button" id="FeiYongLeiXingAn" onclick="addHang()" >
                            <i class="fa fa-plus-square"></i>&nbsp;&nbsp;
                            <span class="bold" >添加</span>
                        </button>
                    </th>
                </tr>
            </thead>
            <tbody id="FeiYongLeiXingList">

            </tbody>
        </table>
         <p style=""><img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt=""><b>客户详情</b>&nbsp;&nbsp;&nbsp;

             <div   id="is_kehuxiangqing">

              </div>
        <script>
            /*console.log('www');
            console.log("{$apply['cp_type']}");
            console.log('www');*/
        </script>

         </p>
        <table class="table table-bordered bud_hei" id="angencyTable" style="display: none;">
            <tr>
                <td><b>{$titlename}</b></td>
            </tr>
        </table>
         <table class="table table-bordered bud_hei" id="netTable" style="display: none;">
             <tr>
                 <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >网点<span class="colorRed">*</span>：</label></td>
                 <td colspan="3">
                     <div class="col-xs-4">
                         <div class="input-group" id="" >
                             <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="net"  value="{:isset($supply)?$supply.jxs:''}">
                             <input type="hidden" name="nets" id="nets"/>
                             <div class="input-group-btn">
                                 <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                 </ul>
                             </div>
                         </div>
                     </div>
                     <div class="col-xs-4">
                         <button class="btn btn-primary btn-sm" id="select_net">选择</button>
                         <input type="button" class="btn btn-primary btn-sm" id="clear_net" value="清空"/>
                         <a href="javascript:;" id="select_my_net">选择我的常用网点分组</a>
                     </div>
                 </td>
             </tr>
             <tr>
                 <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >您选定的网点是：</label></td>
                 <td class="text-left" colspan="3">
                     <div class="duoxuan" id="selected_net">
                         {if isset($list)}
                         {volist name="list.net" id="row"}
                         <span class="ren" data-id="{$row.id}">{$row.title}<span class="close">×</span></span>
                         {/volist}
                         {/if}
                     </div>
                 </td>
             </tr>
            <!--<tr>
                <td>
                     <div class="input-group form-group" id="WangDian" style="display: inline-block;" >

                    </div>
                    &lt;!&ndash;<select class="selectpicker show-menu-arrow" id="WangDianmultiples" style="width:100% ">
                    </select>&ndash;&gt;

                </td>
            </tr>-->
        </table>
        <table class="table table-bordered bud_hei" id="sysTable" >
            <thead>
                <tr class="info">
                    <th class="text-center">系统</th>
                    <th class="text-center">费用占比</th>
                    <th class="text-center">预计投放网点数</th>
                    <th class="text-center">
                        <button class="btn btn-success " type="button" onclick="addHang2()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                        </button>
                    </th>
                </tr>
            </thead>
            <tbody   id="JinXiaoShangZhu">

            </tbody>
        </table>
         <p><img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt=""><b>产品详情</b>&nbsp;&nbsp;&nbsp;
                     <div id="is_changpingxiangqin">

                     </div>

                     <i id="proText">注：产品费用占比加起来必须等于100%,如果不填费用占比则平摊</i>
         </p>


        {if condition="$apply['cp_type'] neq 0"}
        <table class="table table-bordered bud_hei" id="proTable0" style="display: none;">
            {else /}
            <table class="table table-bordered bud_hei active" id="proTable0" >
                {/if}
            <thead>
            <tr class="info">
                <th class="text-center">产品</th>
                <th class="text-center">费用占比</th>
                <th class="text-center">产品说明</th>
                <th class="text-center">
                    <button class="btn btn-success " type="button" onclick="addHang3()">
                        <i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button></th>
            </tr>
            </thead>
            <tbody id="Cpxq0">

            </tbody>
        </table>
        <!--<table class="table table-bordered bud_hei" {if condition="$aid neq 0"} style="display: none;"{/if}  id="proTable1">-->
                <!--<table class="table table-bordered bud_hei" {if condition="$aid neq 0"} style="display: none;"{/if}  id="proTable1">-->
                {if condition="$apply['cp_type'] neq 1"}
                <table class="table table-bordered bud_hei" id="proTable1" style="display: none;">
                    {else /}
                    <table class="table table-bordered bud_hei active" id="proTable1" >
                        {/if}
            <thead>
            <tr class="info">
                <th class="text-center">产品</th>
                <th class="text-center">费用占比</th>
                <th class="text-center">产品说明</th>
                <th class="text-center"> <button class="btn btn-success " type="button" onclick="addHang4()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button></th>
            </tr>
            </thead>
            <tbody id="Cpxq1">

            </tbody>
        </table>
        <!--<table class="table table-bordered bud_hei"  style="display: none;" id="proTable2">-->
        {if condition="$apply['cp_type'] neq 2"}
        <table class="table table-bordered bud_hei" id="proTable2" style="display: none;">
            {else /}
            <table class="table table-bordered bud_hei active" id="proTable2" >
                {/if}
            <thead>
            <tr class="info">
                <th class="text-center">产品</th>
                <th class="text-center">费用占比</th>
                <th class="text-center">产品说明</th>
                <th class="text-center"> <button class="btn btn-success " type="button" onclick="addHang5()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                </button></th>
            </tr>
            </thead>
            <tbody id="Cpxq2">

            </tbody>
        </table>
        <!--<table class="table table-bordered bud_hei"  style="display: none;" id="proTable3">-->
        {if condition="$apply['cp_type'] neq 3"}
        <table class="table table-bordered bud_hei" id="proTable3" style="display: none;">
            {else /}
            <table class="table table-bordered bud_hei active" id="proTable3" >
                {/if}
            <thead>
            <tr class="info">
                <th class="text-center">产品</th>
                <th class="text-center">费用占比</th>
                <th class="text-center">产品说明</th>
                <th class="text-center">
                    <button class="btn btn-success " type="button" onclick="addHang6()">
                        <i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                    </button>
                </th>
            </tr>
            </thead>
            <tbody id="Cpxq3">

            </tbody>
        </table>
        <!--<table class="table table-bordered bud_hei" id="proTable4" style="display: none;">-->
            {if condition="$apply['cp_type'] neq 4"}
            <table class="table table-bordered bud_hei" id="proTable4" style="display: none;">
                {else /}
                <table class="table table-bordered bud_hei active" id="proTable4" >
                    {/if}
            <thead>
                <tr class="info">
                    <th class="text-center">产品1</th>
                    <th class="text-center">产品说明</th>
                    <th class="text-center">
                        <button class="btn btn-success " type="button" onclick="addHang7()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                        </button>
                    </th>
                </tr>
            </thead>
            <tbody id="Cpxq4">

            </tbody>
        </table>

                <!--/ 随货折扣类单品/-->
                <table class="table table-bordered bud_hei" id="proTable42" style="display: none;" >
                    <thead>
                    <tr class="info">
                        <th class="text-center">产品2</th>
                        <th class="text-center">数量</th>
                        <th class="text-center">经销商特价</th>
                        <th class="text-center">产品说明</th>
                        <th class="text-center">
                            <button class="btn btn-success " type="button" onclick="addHang72()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                            </button>
                        </th>
                    </tr>
                    </thead>
                    <tbody id="Cpxq42">

                    </tbody>
                </table>

                <!--/ 产品进场类/-->
                <table class="table table-bordered bud_hei" id="proTable43" style="display: none;">
                    <thead>
                    <tr class="info">
                        <th class="text-center">产品</th>
                        <th class="text-center">零售商供货价</th>
                        <th class="text-center">卖场零售价</th>
                        <th class="text-center">产品说明</th>
                        <th class="text-center">
                            <button class="btn btn-success " type="button" onclick="addHang73()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                            </button>
                        </th>
                    </tr>
                    </thead>
                    <tbody id="Cpxq43">

                    </tbody>
                </table>

                <!--/ 特价补差类/-->
                <table class="table table-bordered bud_hei" id="proTable44" style="display: none;">
                    <thead>
                    <tr class="info">
                        <th class="text-center">产品</th>
                        <th class="text-center">数量</th>
                        <th class="text-center">经销商特价</th>
                        <th class="text-center">系统/网点特价</th>
                        <th class="text-center">零售价</th>
                        <th class="text-center">产品说明</th>
                        <th class="text-center">
                            <button class="btn btn-success " type="button" onclick="addHang74()"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>
                            </button>
                        </th>
                    </tr>

                    </thead>
                    <tbody id="Cpxq44">

                    </tbody>
                </table>


        <p>
            <img  class="titleImg" src="__STATIC__/layout/img/activityXiTong.png" alt="">
            <b>销量预测</b>&nbsp;&nbsp;&nbsp;
            <div id="is_shejixiaoliang">
            </div>

        </p>
        <table class="table table-bordered bud_hei" id="sallycTable">
            <thead>
                <tr class="info">
                    <th class="text-center">预计销售类型</th>
                    <th class="text-center">不做活动销售额</th>
                    <th class="text-center">做活动销售额</th>
                    <th class="text-center">增量销售额</th>
                    <th class="text-center">申请费用额合计</th>
                    <th class="text-center">预计费用率</th>
                </tr>
            </thead>
            <tbody>
                <tr class="text-center">
                    <td>
                        <select name="yjSalesType" id="yjSalesType" class="form-control" style="height: 30px;">
                            <option value="0" {if $apply['yjSalesType']==0} selected {/if}>请选择</option>
                            <option value="1" {if $apply['yjSalesType']==1} selected {/if}>经销商进货</option>
                            <option value="2" {if $apply['yjSalesType']==2} selected {/if}>经销商出货</option>
                            <option value="3" {if $apply['yjSalesType']==3} selected {/if}>网点零售</option>
                        </select>
                    </td>
                    <td>
                         <div class="input-group">
                        <input type="text" id="noSales" name="noSales" {if $apply['noSales']!==''} value="{$apply['noSales']}" {/if} onchange="Saleschange()" class="form-control" aria-label="RMB" style="width: 60px;height: 30px" >
                         <span class="input-group-addon">元</span>
                        </div>
                    </td>
                    <td>
                         <div class="input-group">
                        <input type="text" id="yesSales" name="yesSales" {if $apply['yesSales']!==''} value="{$apply['yesSales']}" {/if} onchange="Saleschange()" class="form-control"  aria-label="RMB" style="width: 60px;height: 30px" >
                         <span class="input-group-addon">元</span>
                        </div>
                    </td>
                    <td id="addSales">{$apply['zl']}</td>
                    <td class="text-right" name="sqfy" id="sqfy">{$apply['hanshui']}</td>
                    <input  type="hidden" name="sqfy"  id="sqfys" >
                    <td class="text-right"  id="yjfyl" >{$apply['feiyonglv']}%</td>
                    <input  type="hidden" name="yjfyl"  id="yjfyls" >
                </tr>
            </tbody>
        </table>

        <input type="button" id="baocunret" class="btn btn-success" value="保存并并返回">

        <input type="button" class="btn btn-warning" value="返回" id="fanhui">


 </form>
<!-- 全局js -->

<script src="__STATIC__/layout/js/contabs_sub.js"></script>

<!-- Sweet alert -->
<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__STATIC__/layout/js/plugins/laydate/laydate.js"></script>

   <!--<script type="text/javascript" src="__STATIC__/layout/js/plugins/select/bootstrap-select.js"></script> -->
    <!-- Chosen -->
<script src="__STATIC__/layout/js/plugins/chosen/chosen.jquery.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>

<script src="__STATIC__/xds/js/time.js"></script>
<script src="__STATIC__/xds/js/select.js"></script>
<script src="__STATIC__/xds/js/tifeiyong.js"></script>
<script src="__STATIC__/xds/js/addTr.js"></script>
<script>

    function baocunadd(){
        console.log('aaa');
        ifInputNull('#baocunadd',function () {
            console.log('1');
            var res=tijiaoyanzheng();
            console.log(res);
            console.log('2');
            if(res["stauts"]==1){
                $.ajax({
                    // cache: false,
                    type: "POST",
                    url:"{:url('TiFeiyong/addapply')}",
                    //data:parent.$('#zhuapply').serialize(),// 你的formid
                    data:$('#form1').serialize(),// 你的formid
                    async: false,
                    /*error: function(request) {
                        alert("Connection error");
                    },*/
                    success: function(data) {
                        var res1=JSON.parse(data);
                        if(res1["state"]==1){
                            swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                            },function(){
                                /*parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))*/
                                parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))

                               // parent.window.location="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();
                                //parent.layer.close(parent.layer.getFrameIndex(window.name))
                                //location.href="{:url('TiApply/addlisthtml')}?aid="+"{$id}"+"&jxs={$jxsid}"+"id="+"{$id}";
                                //parent.window.location="{:url('TiFeiyong/addlisthtml')}?aid="+"{$id}"+"&jxs={$jxsid}"+"id="+"{$id}";


                                /*var index = layer.open({
                                    type: 2,
                                    title: '添加费用明细',
                                    area: ['90%', '90%'],
                                    fixed: false, //不固定
                                    maxmin: true,
                                    /!*btn:["保存","返回"],*!/
                                    content:"{:url('TiFeiyong/addListHtml')}?id="+"{$id}"+"&jxs={$jxsid}"+'&aid='+"{$id}"
//                           content:"{:url('TiFeiyong/addListHtml')}?id="+data.value.id+'&jxsid='+testNoBtn
                                });
                                layer.full(index)*/

                                /*// location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#tiapplyid").val();
                                location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();*/
                            });

                        }else{
                            swal({
                                title: "错误",
                                text:  res1["msg"],
                                type: "warning"
                            });
                        }
                    }
                });
                //baocun()
            }else if(res["stauts"]==2){

                swal('',res["msg"],'warning');
                return false;
            }

        });

    }
    //
    //保存返回
    function baocun(){
        if($("#tiapplyid").val()==""){
            //没有申请
            $.ajax({
                cache: true,
                type: "POST",
                url:"{:url('TiApply/addapply')}",
                data:parent.$('#zhuapply').serialize(),// 你的formid
                async: false,
                error: function(request) {
                    alert("Connection error");
                },
                success: function(data) {
                    //alert(data);
                    var res=JSON.parse(data);
                    $("#tiapplyid").val(res["aid"]);
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url:"{:url('TiApply/addapplydetail')}",
                        data:$('#f1').serialize(),// 你的formid
                        async: false,
                        error: function(requests) {
                            alert("Connection error");
                        },
                        success: function(datas) {
                            //alert(datas);
                            var res1=JSON.parse(datas);
                            if(res1["state"]==1){
                                swal({
                                    title: "完成",
                                    text: "操作已成功",
                                    type: "success"
                                },function(){
                                    parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                    parent.layer.close(parent.layer.getFrameIndex(window.name))
                                });

                            }else{
                                swal({
                                    title: "错误",
                                    text:  res1["msg"],
                                    type: "warning"
                                });
                            }
                        }
                    });
                }
            });
        }else{
            //有申请
            $.ajax({
                cache: true,
                type: "POST",
                url:"{:url('TiApply/addapplydetail')}",
                data:$('#f1').serialize(),// 你的formid
                async: false,
                error: function(requests) {
                    alert("Connection error");
                },
                success: function(datas) {
                    //alert(datas);
                    var res1=JSON.parse(datas);
                    if(res1["state"]==1){
                        swal({
                            title: "完成",
                            text: "操作已成功",
                            type: "success"
                        },function(){
                            parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                            parent.layer.close(parent.layer.getFrameIndex(window.name))
                        });

                    }else{
                        swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                        });
                    }
                }
            });
        }
    }

    //保存并添加
    $("#baocunadd").click(function(){
        console.log('www');
        ifInputNull('#baocunadd',function () {
            console.log('1');
            var res=tijiaoyanzheng();
            console.log(res);
            console.log('2');
            if(res["stauts"]==1){
                $.ajax({
                    // cache: false,
                    type: "POST",
                    url:"{:url('TiFeiyong/addapply')}",
                    //data:parent.$('#zhuapply').serialize(),// 你的formid
                    data:$('#form1').serialize(),// 你的formid
                    async: false,
                    /*error: function(request) {
                        alert("Connection error");
                    },*/
                    success: function(data) {
                        var res1=JSON.parse(data);
                        if(res1["state"]==1){
                            swal({
                                title: "完成2",
                                text: "操作已成功",
                                type: "success"
                            },function(){
                                /*parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))*/


                                parent.window.location="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))
                              //  parent.window.location="{:url('TiFeiyong/addlisthtml')}?aid="+"{$id}"+"&jxs={$jxsid}"+"id="+"{$id}";

                                //var testNoBtn = $("input[name='jxs_id']").val();
                                /*layer.open({
                                    type: 2,
                                    title: '添加费用3明细',
                                    area: ['90%', '90%'],
                                    fixed: false, //不固定
                                    maxmin: true,
                                    /!*btn:["保存","返回"],*!/
                                    content:"{:url('TiFeiyong/addListHtml')}?id="+"{$id}"+'&jxsid='+"{$jxsid}"+'&aid='+"{$id}"
//                           content:"{:url('TiFeiyong/addListHtml')}?id="+data.value.id+'&jxsid='+testNoBtn
                                });*/
                                var index = layer.open({
                                    type: 2,
                                    title: '添加费用明细',
                                    area: ['90%', '90%'],
                                    fixed: false, //不固定
                                    maxmin: true,
                                    content:"{:url('TiFeiyong/addListHtml')}?id="+"{$id}"+"&jxs="+"{$jxsid}"+'&aid='+"{$id}"
                                });
                                layer.full(index)
                                //location.href="{:url('TiApply/addlisthtml')}?aid="+"{$id}"+"&jxs={$jxsid}"+"id="+"{$id}";

                                /*// location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#tiapplyid").val();
                                location.href="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();*/
                            });

                        }else{
                            swal({
                                title: "错误",
                                text:  res1["msg"],
                                type: "warning"
                            });
                        }
                    }
                });
            }else if(res["stauts"]==2){
                swal('',res["msg"],'warning');
                return false;
            }

        });

    })

    //保存返回
    $("#baocunret").click(function(){
        console.log('www');
        ifInputNull('#baocunadd',function () {
            console.log('1');
            var res=tijiaoyanzheng();
            console.log(res);
            console.log('2');
            if(res["stauts"]==1){
                $.ajax({
                    // cache: false,
                    type: "POST",
                    url:"{:url('TiFeiyong/addapply')}",
                    url:"{:url('TiFeiyong/updateapply')}",
                    //data:parent.$('#zhuapply').serialize(),// 你的formid
                    data:$('#form1').serialize(),// 你的formid
                    async: false,
                    success: function(data) {
                        var res1=JSON.parse(data);
                        if(res1["state"]==1){
                            swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                            },function(){

                                parent.window.location="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))
                            });

                        }else{
                            swal({
                                title: "错误",
                                text:  res1["msg"],
                                type: "warning"
                            });
                        }
                    }

                });

                //baocun()
            }else if(res["stauts"]==2){

                swal('',res["msg"],'warning');
                return false;

                /*swal({
                    title: "错误",
                    text:  res["msg"],
                    type: "warning"
                });*/
            }

        });
    })

    //返回
    $('#fanhui').click(function () {
        parent.window.location="{:url('TiFeiyong/addinfohtml')}?aid="+$("#ti_id").val();
    })

    function tijiaoyanzheng(){
        $(".num2").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                $(this).val("0.00");
            }else{
                $(this).val(parseFloat($(this).val()).toFixed(2));
            }
        })
        //验证网点
        var message=[];
        var netarr=[];
        var num=0;
        $(".netlist").each(function(){
            netarr.push($(this).attr("data-id"));

        })
        $("#nets").val(netarr.join(','));
        //产品
        var proarr=[];
        $(".prolist").each(function(){
            proarr.push($(this).attr("data-id"));
        })
        $("#pros").val(proarr.join(','));
        if($("#yujihexiaotime").val()==""){
            message["msg"]="预计核销日期必须填写";message["stauts"]=2;
            return message;
        }
        if($("#hdjs").val()==""){
            message["msg"]="活动简述及目的必须填写";message["stauts"]=2;
            return message;
        }

        if($("#start").val()==""){
            message["msg"]="促销开始时间必须填写";message["stauts"]=2;
            return message;
        }
        if($("#end").val()==""){
            message["msg"]="促销结束时间必须填写";message["stauts"]=2;
            return message;
        }

        if($("#pros").val()==""){
            message["msg"]="至少选择一个产品";message["stauts"]=2;
            return message;
        }
        //费用记录不能为空
        var ck=1;
        $(".feetype").each(function(){
            num++;
            if($(this).val()==""){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="费用名称必须填写";message["stauts"]=2;
            return message;
        }
        ck=1;
        $(".zonge").each(function(){
            if($(this).val()==""||$(this).val()=="0"){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="未税总额必须填写并且不能为0";message["stauts"]=2;
            return message;
        }
        ck=1;
        $(".paymethod").each(function(){
            if($(this).val()==0){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="支付方式必须选择";message["stauts"]=2;
            return message;
        }
        ck=1;
        $(".jrbm[name='jrbm']").each(function(){
            if($(this).val()==""){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="费用计入部门必须选择";message["stauts"]=2;
            return message;
        }
        ck=1;
        $(".project").each(function(){
            if($(this).val()=="0"){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="费用计入方案必须选择";message["stauts"]=2;
            return message;
        }
        //至少一项费用num统计次数
        var zongji=0;
        $(".zonge").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                zongji+=0;
            }else{
                zongji+=parseFloat($(this).val());
            }
        })
        zongji+=parseFloat($("#sumjian").val());
        if(zongji==0){
            message["msg"]="至少有一项费用且费用不能为0";message["stauts"]=2;
            return message;
        }
        ///验证产品项
        //预计销量
        ck=1;
        $(".boxs").each(function(){
            if(parseFloat($(this).val())==0){
                ck=0;
            }
        })
        if(ck==0){
            message["msg"]="预计销量不能为0";message["stauts"]=2;
            return message;
        }
        //现经销商价不能为空xianjsx
        ck=1;
        $(".xianjsx").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="经销商现供货价不能为空";message["stauts"]=2;
            return message;
        }
        //网点原供货价
        ck=1;
        $(".netyuan").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="网点原供货价不能为空";message["stauts"]=2;
            return message;
        }
        //网点现
        ck=1;
        $(".xiannet").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="网点现供货价不能为空";message["stauts"]=2;
            return message;
        }
        //原零售价
        ck=1;
        $(".yuanp").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="原零售价不能为空";message["stauts"]=2;
            return message;
        }
        //现零售价
        ck=1;
        $(".xianp").each(function(){
            if(isNaN(parseFloat($(this).val()))){
                ck=0;return false;
            }else{
                if(parseFloat($(this).val())==0){
                    ck=0;return false;
                }
            }
        })
        if(ck==0){
            message["msg"]="促销零售价不能为空";message["stauts"]=2;
            return message;
        }
        ck=0;

        message["msg"]="";message["stauts"]=1;
        return message;
    }

        $(function () {
            $('body').on('click','input[type=text]',function () {
                this.select()
            })
        })


    //弹出选择网点框

    //弹出选择网点框
    $('#select_net').on('click',function () {
        var index = layer.getFrameIndex(window.name)
        layer.open({
            type:2,
            area:['60%','60%'],
            maxmin:true,
            content:'{:url("selectNet")}?index='+index+'&keyword={$jxsid}'
        })
        return  false
    })

    $(document).on("click",".netlist .close",function(){
        $(this).parent().remove();
    })

    $("#clear_net").click(function(){
        $(".netlist").remove();
    })





        $(document).on("click","input[name=options]",function(){
            $(this).parent('label').siblings().removeClass('active')
            $(this).parent('label').addClass('active')
        })


        //费用类型

    function mu(type,id) {
        if(type==1){
            $('#myModal1'+id).modal('show');
            $('#xgcbzx'+id).show();
        }
    }
    function gradeChange(id){
        console.log('gradeChange')
        var k = 'state'+id;
        var type = $("#"+k).find("option:selected").attr("grade");

        if(type==1){
            $('#myModal1'+id).modal('show');
            $('#xgcbzx'+id).show();
        }else {
            $('#xgcbzx'+id).hide();
        }
    }

        function tijiao(id) {

            var l = '';
            var m = 0;
            var sum = 0;
            $('.divTid'+id).each(function () {

                sum += Number($(this).find('.inpbai').val());
            });
            if(sum!=100){m =2;};
            $('.divTid'+id).each(function () {
                if($(this).find('.inpbai').val()==''||$(this).find('.inpbai').val()==0){
                    var z =  $(this).find('.uiName').text();
                    if(l==''){
                        l += z;
                    }else {
                        l += ','+ z;
                    }
                    m = 1;
                }

            });
            if(m==1){
                swal('',l+'，请填写占比！','warning');
            }else if(m==2){
                swal('','占比加起来必须等于100%！','warning');
            }else {
                alert('提交成功');
                $("#myModal"+id).modal('hide');

                var str2= '';
                var str3= '';
                $('.divTid'+id).each(function () {
                    var uiName=$(this).find('.uiName').text();
                    var  tid = $(this).find('.uiName').siblings('input').attr('tid');
                    var inpbai=$(this).find('.inpbai').val()
                    str2 += '<p class="psClassName" psid="'+tid+'" psTo="'+inpbai+'"><span>'+uiName+'</span>,'+inpbai+'%</p>'
                    if(str3==''){
                        str3 = uiName+','+inpbai+'%';
                    }else {
                        str3 +=';'+ uiName+','+inpbai+'%';
                    }
                });
                str2 = str2+'<input name="cbzx'+id+'" value="'+str3+'" type="hidden"/>';

                $("#showSelectText"+id).html(str2);
            }
        }
        function tijiao2(id) {
        //货补清单 提交后把数据提交到页面
            console.log(id);
            var data="";
            ifInputNull('#YpWl',function () {
                console.log('w');
                var formData = $('#YpWlform'+id).serialize();
                console.log(formData);
                console.log('x');

            })

            $.ajax({
                // cache: false,
                type: "POST",
                url:"{:url('TiFeiyong/deal_hb')}",
//                data:$('#form1').serialize(),// 你的formid
                data:$('#YpWlform'+id).serialize(),
                async: false,
                /*error: function(request) {
                    alert("Connection error");
                },*/
                success: function(data) {
                    var res1=JSON.parse(data);
                    if(res1["state"]==1){
                        $("#myModal1"+id).modal('hide');
                        $("#fRmb"+id).val(res1['sum']);
                        $("#hbxx"+id).val(res1['info']);
                        console.log(id,'id22id')

                        var yjall=0;
                        $(".fRmb").each(function(){
                            var fRmb =$(this).val();
                            yjall=Number(yjall)+Number(fRmb);
                        })
                        $("#sqfy").text(yjall);

                    }else{
                        swal({
                            title: "错误",
                            text:  '数据不完整，请完善！',
                            type: "warning"
                        });
                    }
                }

            });

            var YpWl='YpWl'+id;
            $("#"+YpWl+">tr").each(function(){
                var units = $(this).children('td').find('.units').text();
                var factorys = $(this).children('td').find('.factorys').text();

                var units2 = $(this).children('td').children('').find('.units').text();
                var factorys2 = $(this).children('td').children('').find('.factorys').text();

                if(units){
                    if(data==''){
                        data+='unit:'+units;
                    }else {
                        data+="||"+'unit:'+units;
                    }
                }

            });

        }

    function wlnum_to(id){

        if(id<10){
            id='0'+id;
        }

        var wlnum=$('#wlnum'+id).val();
        console.log(wlnum,'wlnum',id)
        if(wlnum!=''){
            var factory = $('#factory'+id).text();
            var all = wlnum * factory;
            $('#allmoney'+id).text(all);
            $('#allmoneys'+id).val(all);
        }else{
        }
    }
        function del_this(obj,id) {
                console.log(obj.parent().parent().siblings());
                if(obj.parent().parent().siblings().length<1){

                    alert("至少保留一行")
                }else{

                    $(id).remove();

                }

        }
        function setSelect(id){
            var strtext = $('#multiples'+id).select2('data');
            var a=[];
            for(var i=0;i<strtext.length;i++){
                a[strtext[i].id] = strtext[i].text;

            }
            var b=[];
            $("#selectDiv"+id+" .divTid").each(function(){
                b[$(this).attr('tid')]=$(this).find('.inpbai').val();
            })
            var str = '' ;
            o = 0;
            for(key in a){
                o++;
                if(b.hasOwnProperty(key)){
                    str += '<div class="padding-10 divTid'+id+'" tid="'+key+'">'+
                        '<div class="form-group"><input class="tid" type="hidden" value="'+key+'"/>'+o+'.<span class="uiName">'+a[key]+'</span></div>'+
                        '<div class="form-group" style="float: right;">'+
                        '<div class="input-group">'+
                        '<input type="text" class="form-control inpbai" aria-label="%" style="width: 60px;height: 30px" value="'+b[key]+'" >'+
                        '<span class="input-group-addon">%</span>'+
                        '</div>'+
                        '</div>'+
                        '</div>';
                }else{
                    str += '<div class="padding-10 divTid'+id+'" tid="'+key+'">'+
                        '<div class="form-group"><input class="tid" value="'+key+'" style="display: none"/>'+o+'.<span class="uiName">'+a[key]+'</span></div>'+
                        '<div class="form-group" style="float: right;">'+
                        '<div class="input-group">'+
                        '<input type="text" class="form-control inpbai" aria-label="%" style="width: 60px;height: 30px" value="" >'+
                        '<span class="input-group-addon">%</span>'+
                        '</div>'+
                        '</div>'+
                        '</div>';
                }
            }

            $("#selectDiv"+id).html(str);
        }
    function h(id) {
        entranceX2x('wlName'+id,
            "{:url('select/materialjson')}?id="+0,
            '',function (data) {
                $(this).val(data.id);
                $(this).closest('.input-group').hide();

                $(this).closest('.input-group').hide();
                $('#select'+id).show().find('.inin').html(data.key);
                var rs = $('#thisWL'+id).attr('rs');
                rs = JSON.parse(rs);

                for(var i=0;i<rs.length;i++){
                    if(rs[i].id==data.id){
                        $('.unit'+id).html(rs[i].unit)
                        $('.factory'+id).html(rs[i].factory)
                    }
                }
            }

        );

        entranceX2x('wlName2'+id,
            "{:url('select/materialjson')}?id="+1,
            '',function (data) {
                $(this).val(data.id);
                $(this).closest('.input-group').hide();

                $(this).closest('.input-group').hide();
                $('#select'+id).show().find('.inin').html(data.key);
                var rs = $('#thisWL'+id).attr('rs2');
                rs = JSON.parse(rs);

                for(var i=0;i<rs.length;i++){
                    if(rs[i].id==data.id){
                        $('.unit'+id).html(rs[i].unit)
                        $('.factory'+id).html(rs[i].factory)
                    }
                }
            },2
        );




    }
        function a(id,num) {  //是uploadTr(feiyongxiagqing,'#FeiYongLeiXingList','',a,title);中的回调函数

           var al = 'feetype'+id;

           var s2 =  '{:url("BiHaiChaoSheng/selectList",["url"=>"Tifykm","where"=>"esuseway_2__channeltypes_$channeltype"])}?str='+al;

//"{:url('BiHaiChaoSheng/AjaxFYKU2',['fylx'=>$fylx,'channeltypes'=>$channeltype])}",
           entranceX('feetype'+id,
                "{:url('BiHaiChaoSheng/AjaxFYKU',['esuseway'=>'2','channeltypes'=>$channeltype])}",
                s2,
                '',function () {
                    if($("input[name=feetype"+id+"]").val()==''){
                        $('#isNull'+id).nextAll().remove();
                    }
                    else {  //
                        var FeiYonglxVal = $("input[name=feetype"+id+"]").val();
                        var FeiYonglxUrl = "{:url('BiHaiChaoSheng/get3KmDyfkfs')}?id="+FeiYonglxVal; //选择费用类型
                        $.ajax({
                            url: FeiYonglxUrl,
                            type: 'get',
                            dataType: 'json',
                            success: function(data) {
                                if(data.code==200){
                                    var zi = '';
                                    var value = data.value;
                                    for (var i =0;i<value.length;i++){
                                        var zfvalue = $("#state"+id).attr("data-id");  //
                                        if(value[i].id==zfvalue){
                                            zi+='<option method="'+value[i].method+'" grade="'+value[i].method+'" selected="selected" onclick="mu('+value[i].method+','+id+')"  value="'+value[i].id+'">'+value[i].title+'</option>';
                                        }else {
                                            zi+='<option method="'+value[i].method+'" grade="'+value[i].method+'" onclick="mu('+value[i].method+','+id+')"  value="'+value[i].id+'">'+value[i].title+'</option>';
                                        }
//                                        zi+='<option method="'+value[i].method+'" grade="'+value[i].method+'" onclick="mu('+value[i].method+','+id+')"  value="'+value[i].id+'">'+value[i].title+'</option>';
                                    }   // onclick="mu( 未点击事件，当选择时弹出
                                    $('#isNull'+id).after(zi);
                                    $('#xgcbzx'+id).on('click',function () {
                                        $('#myModal1'+id).modal('show');
                                    });

                                    if(data.chenlie==1){
                                        //如果陈列方式是1，则在费用说明中显示陈列方式
                                        $('#cl_type'+id).show();
                                        $('#cl_place'+id).show();
                                        $('#cl_size'+id).show();
                                        //alert('qq');
                                    }else{
                                        //如果陈列方式是0，则在费用说明中隐藏陈列方式
                                        $('#cl_type'+id).hide();
                                        $('#cl_place'+id).hide();
                                        $('#cl_size'+id).hide();
                                    }

                                    $('#addyw'+id).on('click',function () {
                                        $('#myModal1'+id).modal('show');
                                    });

                                    $("#addyw"+id).click(function(){   //添加样品物料
                                        console.log('addyw2');
                                        var date= Date.parse(new Date());
                                        uploadTr(yangpingwuliao,'#YpWl'+id,'',h);
                                        /*var str='<tr>'+
                                            '<td>'+
                                            '<div class="btn-group" style="border: 1px solid #ccc;border-radius: 6px;">'+
                                            '<label class="btn btn-white" style="position: relative;">'+
                                            '<input type="radio" name="options" id="option'+date+'" '+
                                            'autocomplete="off" style="opacity: 0;position: absolute;">进货'+
                                            '</label>'+
                                            '<label class="btn btn-white active" style="position: relative;">'+
                                            '<input type="radio" name="options" id="option2'+date+'" autocomplete="off" checked style="opacity: 0;position: absolute;"> 不进货'+
                                            '</label>'+
                                            '</div>'+
                                            '</td>'+
                                            '<td>'+
                                            '<input type="text" class="form-control">'+
                                            '</td>'+
                                            '<td><input type="text" class="form-control" style="width: 80px"></td>'+
                                            '<td></td>'+
                                            '<td></td>'+
                                            '<td></td>'+
                                            '<td>'+
                                            '<a class="btn btn-danger btn-bitbucket " onclick="del_this($(this),'+id+')">'+
                                            '<i class="fa fa-trash-o"></i> 删除'+
                                            '</a>'+
                                            '</td>'+
                                            '</tr>';
                                        $("#ywTable"+id).append(str)*/
                                    })

                                    //添加成本中心




                                }
                            }
                        });

                    }

                });
            $('#is_shoukuanF'+id).AddRadioX(
                [
                    {
                        title:'经销商',
                        name:'is_jinxiao',
                        className:'jinxiao',
                        isTrue:false,
                        value:1,
                        fun:function (obj) {
                            $(obj).click(function(){
                                $(this).parent('label').siblings().removeClass('active');
                                $(this).parent('label').addClass('active');
//                                $('input[name=payee'+id+']').val('{$jxsid}');
                                $('input[name=payee'+id+']').val('-1');//当值为-1时，选取的为经销商，并且经销商的值通过jxs_id获取
                                $("#payee"+id).hide();

                            });
                        }
                    },
                    {
                        title:'供应商',
                        name:'is_gonghuo',
                        className:'gonghuo',
                        isTrue:true,
                        value:0,
                        fun:function (obj) {
                            $(obj).click(function(){
                                $(this).parent('label').siblings().removeClass('active')
                                $(this).parent('label').addClass('active');
                                closeX('payee'+id);
                                $("#payee"+id).show();
                            })

                        }
                    }

                ]
            );
            entranceX2('payee'+id,
                "{:url('BiHaiChaoSheng/getGYS')}",
                '');
            entranceX2('cl_type'+id,
                "{:url('BiHaiChaoSheng/AjaxCL',['type'=>1])}",
                '','','陈列类型');
            entranceX2('cl_place'+id,
                "{:url('BiHaiChaoSheng/AjaxCL',['type'=>2])}",
                '','','陈列位置');
            entranceX2('cl_size'+id,
                "{:url('BiHaiChaoSheng/AjaxCL',['type'=>3])}",
                '','','陈列尺寸');

            $("#multiples"+id).select2({
                ajax: {
                    /*url: "{:url('BiHaiChaoSheng/ajaxJXSALL')}",*/
                    url: "{:url('BiHaiChaoSheng/ajaxZoningALL')}",
                    dataType: 'json',
                    data: function (params) {
                        console.log('ee')
                        console.log(params)
                        console.log('rr')
                        var query = { //请求的参数, 关键字和搜索条件之类的
                            search: params.term //select搜索框里面的value
                        }
                        console.log(query)
                        // Query paramters will be ?search=[term]&page=[page]
                        return query;
                    },
                    delay: 1500,
                    processResults: function (data, params) {
                        //返回的选项必须处理成以下格式
                        //var results =  [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }];
                        var results = data;
                        return {
                            results: results  //必须赋值给results并且必须返回一个obj
                        };
                    }

                },
                allowClear: true,
                multiple: true
            }).on("change",function(){
                setSelect(id);

            });

            $("#WangDianmultiples").select2({
                ajax: {
                    /*url: "{:url('BiHaiChaoSheng/ajaxJXSALL')}",*/
                    /*url: "{:url('BiHaiChaoSheng/ajaxZoningALL')}",*/
                    url: "{:url('BiHaiChaoSheng/ajaxNetALL')}",
                    dataType: 'json',
                    data: function (params) {
                        console.log('ee')
                        console.log(params)
                        console.log('rr')
                        var query = { //请求的参数, 关键字和搜索条件之类的
                            search: params.term //select搜索框里面的value
                        }
                        console.log(query)
                        // Query paramters will be ?search=[term]&page=[page]
                        return query;
                    },
                    delay: 1500,
                    processResults: function (data, params) {
                        //返回的选项必须处理成以下格式
                        //var results =  [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }];
                        var results = data;
                        return {
                            results: results  //必须赋值给results并且必须返回一个obj
                        };
                    }

                },
                allowClear: true,
                multiple: true
            }).on("change",function(){
                setSelect(id);

            });


            $("#multiples"+id).val([10001,10003]).trigger('change');
            setSelect(id);

        }

        var title="{$title}";
        //uploadTr(feiyongxiagqing,'#FeiYongLeiXingList','',a);//把选中的经销商对应到成本中心中
        /*uploadTr(feiyongxiagqing,'#FeiYongLeiXingList','',a,title);//把选中的经销商对应到成本中心中*/
        //在新更新的成本中心更改为所选的活动经销商

        /*添加一行*/
        function addHang(){
            uploadTr(feiyongxiagqing,'#FeiYongLeiXingList','',a,title); // 参数title是新增的字段只为更改成本中心
        }
        //客户详情
            //系统
            function b(id) {
                /*entranceX('JinXiaoShang'+id,
                    "{:url('BiHaiChaoSheng/AjaxJXS',['jxs'=>$channeltype])}",
                    '{:url("BiHaiChaoSheng/selectList",["url"=>"Tixt","where"=>"jxs_$channeltype"])}?str=JinXiaoShang'+id,
                    '',
                    '');*/
                /*entranceX('JinXiaoShang'+id,
                    "{:url('BiHaiChaoSheng/AjaxJXS',['jxs'=>$jxsid])}", // 'jxs'=>$jxsid] 通过所选的活动经销商
                    '{:url("BiHaiChaoSheng/selectList",["url"=>"Tixt","where"=>"jxs_$jxsid"])}?str=JinXiaoShang'+id,
                    '',
                    '');*/

                entranceX('JinXiaoShang'+id,
                    "{:url('BiHaiChaoSheng/AjaxJXS',['jxs'=>$jxsid])}",  //// 'jxs'=>$jxsid] 通过所选的活动经销商
                    '{:url("BiHaiChaoSheng/selectList",["url"=>"Tixt","where"=>"jxs_$jxsid"])}?str=JinXiaoShang'+id,
                    '',
                    '');

            }
            /*uploadTr(kehuxiaongqingXitong,'#JinXiaoShangZhu','',b)*/
            function addHang2(){
                uploadTr(kehuxiaongqingXitong,'#JinXiaoShangZhu','',b)
            }
           // 网点
            entranceX('WangDian',
                "{:url('BiHaiChaoSheng/AjaxWD',['jxs'=>$jxsid])}",  //// 'jxs'=>$jxsid] 通过所选的活动经销商
                '{:url("BiHaiChaoSheng/selectList",["str"=>"WangDian","url"=>"Tiwd","where"=>"jxs_$jxsid"])}',
                '',
                '');

    //产品网点搜索自动补全
    $("#net").bsSuggest({
        url: "{:url('netjson2')}?jid="+{$jxsid},
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_net .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_net').append('<span class="ren netlist" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });





        //产品详情
            function showTable(obj,su){
                obj.parent('label').siblings('label').removeClass('active')
                obj.parent('label').addClass('active');
                for (var io =0;io<5;io++){
                    $("#proTable"+io).hide();

                    /*console.log(io)*/
                }
                $("#proTable"+su).show();
                if(su==4){
                    $("#proText").text("注：如选择单品类，则各单品费用将会平摊。如不希望平摊，请填写多次明细。");
                }else {
                    $("#proText").text("注：产品费用占比加起来必须等于100%,如果不填费用占比则平摊");
                }

            }
            //品牌
            function c(id) {
                entranceX('proTableInput0'+id,
                    "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>1])}",
                    '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_1"])}?str=proTableInput0'+id,
                    '',
                    '');
            }
            /*uploadTr(changpingxianqin1,'#Cpxq0','',c);*/
            function addHang3(){
                uploadTr(changpingxianqin1,'#Cpxq0','',c);
            }
            //品类
            function d(id) {
                entranceX('proTableInput1'+id,
                    "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>2])}",
                    '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_2"])}?str=proTableInput1'+id,
                    '',
                    '');
            }
           /* uploadTr(changpingxianqin2,'#Cpxq1','',d);*/
            function addHang4(){
                uploadTr(changpingxianqin2,'#Cpxq1','',d);
            }
            //系列
            function e(id,name) {
                entranceX('proTableInput2'+id,
                    "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>3])}",
                    '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_3"])}?str=proTableInput2'+id,
                    '',
                    '');
            }

            function changpingxianqin3(obj) {
                return  '<tr class="text-center">\n' +
                    '                <td id="proTableInput2{#id}">\n' +
                    '\n' +
                    '                </td>\n' +
                    '\n' +
                    '                <td>\n' +
                    '                    <div class="input-group">\n' +
                    '                        <input type="text" class="form-control"  name="proTableInputBl2{#id}" id="proTableInputBl2{#id}" aria-label="" style="width: 60px;height: 30px">\n' +
                    '                        <span class="input-group-addon">%</span>\n' +
                    '                    </div>\n' +
                    '                </td>\n' +
                    '                <td>\n' +
                    '                    <input type="text" class="form-control" name="proTableInputSm2{#id}" id="proTableInputSm2{#id}" placeholder="简要说明产品">\n' +
                    '                </td>\n' +
                    '                <td>\n' +
                    '                    <a class="btn btn-white btn-bitbucket">\n' +
                    '                        <i class="fa fa-trash-o"></i> 删除\n' +
                    '                    </a>\n' +
                    '                </td>\n' +
                    '            </tr>';
            }


//            var objString = JSON.stringify({name: 'xiaoqiang', age: 123})
//            uploadTr(changpingxianqin3.replace('class="text-center"', 'class="text-center" data-main=\''+ objString +'\''),'#Cpxq2','',e);
            function addHang5(obj){
                uploadTr(changpingxianqin3(obj),'#Cpxq2','',e);
            }
            //Sku
            function f(id) {
                entranceX('proTableInput3'+id,
                    "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>4])}",
                    '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_4"])}?str=proTableInput3'+id,
                    '',
                    '');
            }
            /*uploadTr(changpingxianqin4,'#Cpxq3','',f);*/
            function addHang6(){
                uploadTr(changpingxianqin4,'#Cpxq3','',f);
            }
            //单品
            function g(id) {
                entranceX('proTableInput4'+id,
                    "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>5])}",
                    '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_5"])}?str=proTableInput4'+id,
                    '',
                    '');
            }

    //单品 随货折扣类
    function g2(id) {
        entranceX4('proTableInput4'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>5,'jxs'=>$jxsid])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_5__jxs_$jxsid","type"=>2])}?str=proTableInput4'+id,
            '',
            '',2);
    }
    //单品 随货折扣类
    function g3(id) {
        entranceX4('proTableInput4'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>5,'jxs'=>$jxsid])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_5__jxs_$jxsid"])}?str=proTableInput4'+id,
            '',
            '',7);
    }

    //单品 特价补差类
    function g4(id) {
        entranceX4('proTableInput4'+id,
            "{:url('BiHaiChaoSheng/getCp',['type'=>2,'style'=>5,'jxs'=>$jxsid])}",
            '{:url("BiHaiChaoSheng/selectList",["url"=>"getCp","where"=>"type_1__style_5__jxs_$jxsid"])}?str=proTableInput4'+id,
            '',
            '',4);
    }

            /*uploadTr(changpingxianqin5,'#Cpxq4','',g);*/
            function addHang7(){
                uploadTr(changpingxianqin5,'#Cpxq4','',g);
            }

            function addHang72(){  //随货折扣类
                uploadTr(changpingxianqin6,'#Cpxq42','',g2);
            }
            function addHang73(){  //产品进场类
                uploadTr(changpingxianqin7,'#Cpxq43','',g3);
            }
            function addHang74(){  //特价补差类
                uploadTr(changpingxianqin8,'#Cpxq44','',g4);
            }


            function fRmbchange() {
                var yjall=0;
                $(".fRmb").each(function(){
                    var fRmb =$(this).val();
                    yjall=Number(yjall)+Number(fRmb);
                    //yjall=yjall + fRmb;
                })

                $("#sqfy").text(yjall);
            }

            function Saleschange() {

                var noS =$("#noSales").val();
                var yesS =$("#yesSales").val();
                if(noS!='' && yesS!=''){
                    var addS = Number(yesS)-Number(noS);
                    $("#addSales").text(addS);
                }
                var sqfy =$("#sqfy").text();
                if(sqfy!='' && yesS!=''){
                    var fl = 100*Number(sqfy)/Number(yesS);
                    $("#yjfyls").val(fl);
                    fl=fl+'%';
                    $("#yjfyl").text(fl);
                    //
                }

            }


    /*$('.fRmb').on('change',function () {
        console.log('aa');
        var id = $(this).val()
        console.log(id);
        console.log('bb');
        //$('#jxs').load('{:url("getjxses")}?id='+id)
    })*/
            
            
        //选择按钮
        $('#is_shejixiaoliang').AddRadioX(
            [
                {
                    title:'涉及销量',
                    name:'is_shejixiaoliang',
                    className:'shengji',
                    //isTrue:false,
                    isTrue:true,
                    value:1,
                    fun:function (obj) {
                        $(obj).click(function(){
                            $(this).parent('label').siblings('label').removeClass('active')
                            $(this).parent('label').addClass('active');
                            $("#sallycTable tbody tr td").find('input').attr('disabled',false);
                            $("#sallycTable tbody tr td").find('select').attr('disabled',false);
                        });
                    }
                },
                {
                    title:'不涉及销量',
                    name:'is_shejixiaoliang',
                    className:'busheji',
                    //isTrue:true,
                    isTrue:false,
                    value:0,
                    fun:function (obj) {
                        $(obj).click(function(){
                            $(this).parent('label').siblings('label').removeClass('active')
                            $(this).parent('label').addClass('active');
                            $("#sallycTable tbody tr td").find('input').attr('disabled',true);
                            $("#sallycTable tbody tr td").find('select').attr('disabled',true);
                        })
                    }
                }

            ]
        );
            //AddRadioX
        $('#is_kehuxiangqing').AddRadioX(   //$('#is_kehuxiangqing').AddRadioX(
            [
                {
                    title:'经销商',
                    name:'is_kehuxiangqing',
                    className:'khjinxiaoshnag',
                    isTrue:false,
                    value:1,
                    fun:function (obj) {
                        $(obj).click(function(){
                            $(this).parent('label').siblings('label').removeClass('active')
                            $(this).parent('label').addClass('active')
                            $("#angencyTable").show();
                            $("#sysTable").hide();
                            $("#netTable").hide();
                            $(".netlist").remove();
                            $("#JinXiaoShangZhu").empty();
                            $("#khxqtype").val('1');
                        });
                    }
                },
                {
                    title:'系统',
                    name:'is_kehuxiangqing',
                    className:'khxitong',
                    isTrue:true,
                    value:0,
                    fun:function (obj) {
                        $(obj).click(function(){
                            $(this).parent('label').siblings('label').removeClass('active');
                            $(this).parent('label').addClass('active');
                            $("#angencyTable").hide();
                            $("#sysTable").show();
                            $("#netTable").hide();
                            $(".netlist").remove();
                            addHang2();
                            $("#khxqtype").val('2');
                        })

                    }
                },
                {
                    title:'网点',
                    name:'is_kehuxiangqing',
                    className:'khwangdian',
                    isTrue:false,
                    value:0,
                    fun:function (obj) {
                        $(obj).click(function(){
                            $(this).parent('label').siblings('label').removeClass('active')
                            $(this).parent('label').addClass('active')
                            $("#angencyTable").hide();
                            $("#sysTable").hide();
                            $("#netTable").show();
                            $("#JinXiaoShangZhu").empty();
                            $("#khxqtype").val('3');
                        })

                    }
                }

            ]
        );
        $('#is_changpingxiangqin').AddRadioX(
            [
                {
                    title:'品牌',
                    name:'is_cpxq',
                    className:'cpxqpp',
                    isTrue:true,
                    value:1,
                    fun:function (obj) {
                        $(obj).click(function(){
                            showTable($(this),0);
                            $("#Cpxq0").empty();
                            $("#Cpxq1").empty();
                            $("#Cpxq2").empty();
                            $("#Cpxq3").empty();
                            $("#Cpxq4").empty();
                            addHang3();
                            addHang3();
                            $("#cpxqtype").val('1');

                        });
                    }
                },
                {
                    title:'品类',
                    name:'is_cpxq',
                    className:'cpxqpl',
                    isTrue:false,
                    value:0,
                    fun:function (obj) {
                        $(obj).click(function(){
                            showTable($(this),1);
                            $("#Cpxq0").empty();
                            $("#Cpxq1").empty();
                            $("#Cpxq2").empty();
                            $("#Cpxq3").empty();
                            $("#Cpxq4").empty();
                            addHang4();
                            $("#cpxqtype").val('2');
                        })

                    }
                },
                {
                    title:'系列',
                    name:'is_cpxq',
                    className:'cpxqxl',
                    isTrue:false,
                    value:0,
                    fun:function (obj) {
                        $(obj).click(function(){
                            showTable($(this),2);
                            $("#Cpxq0").empty();
                            $("#Cpxq1").empty();
                            $("#Cpxq2").empty();
                            $("#Cpxq3").empty();
                            $("#Cpxq4").empty();

                            addHang5();
                            $("#cpxqtype").val('3');
                        })

                    }
                },
                {
                    title:'SKU',
                    name:'is_cpxq',
                    className:'cpxqsku',
                    isTrue:false,
                    value:0,
                    fun:function (obj) {
                        $(obj).click(function(){
                            showTable($(this),3);
                            $("#Cpxq0").empty();
                            $("#Cpxq1").empty();
                            $("#Cpxq2").empty();
                            $("#Cpxq3").empty();
                            $("#Cpxq4").empty();
                            addHang6();
                            $("#cpxqtype").val('4');
                        })

                    }
                },
                {
                    title:'单品',
                    name:'is_cpxq',
                    className:'cpxqdp',
                    isTrue:false,
                    value:0,
                    fun:function (obj) {
                        $(obj).click(function(){
                            showTable($(this),4);
                            $("#Cpxq0").empty();
                            $("#Cpxq1").empty();
                            $("#Cpxq2").empty();
                            $("#Cpxq3").empty();
                            $("#Cpxq4").empty();
                            addHang7();
                            $("#cpxqtype").val('5');
                        })

                    }
                }

            ]
        );


    //删除费用科目项
    $('body').on('click','.del_fi_item',function () {
        $(this).closest('tr').remove()
    })
//删除
    $('body').on('click','.btn-bitbucket',function () {
        $(this).closest('tr').remove()
    })


    function getHsonLength(json){
        var jsonLength=0;
        for (var i in json) {
            jsonLength++;
        }
        return jsonLength;
    }

    function test(id,value) {
        /*console.log('id');
        console.log($('#'+id)[0].length)*/
        var opts=document.getElementById(id)
        var leng=$('#'+id)[0].length;
        for(var k=0;k<leng;k++){

//            console.log(opts.options[k].text)

            if(value==opts.options[k].value){
                console.log('logtest')
//                console.log(k);
                opts.options[k].selected = 'selected';
                break;
            }
        }


    }


    $(document).ready(function () {
        //销量预测
        var is_xiaoliang="{$apply['is_shejixiaoliang']}";

        if(is_xiaoliang==1){
            $('#is_changpingxiangqin').find("label").eq(0).addClass('active')
            $('#is_changpingxiangqin').find("label").eq(1).removeClass('active')

        }else {
            $('#is_changpingxiangqin').find("label").eq(1).addClass('active')
            $('#is_changpingxiangqin').find("label").eq(0).removeClass('active')
        }

        //费用详情
        var data = JSON.parse('{$fee}');
        for(var i=0;i<data.length;i++){
            var hb=data[i]['hbinfo'];
            var hbtype=data[i]['hbtype'];

            //console.log(hb,'hb')
            var hbxq = '';
            if(hbtype==1){  //有货补数据
                for(var j=0;j<hb.length;j++){
                    if(hb[j]['wlyptype']==1){
//  +j+   +i+j+
                        var hbxq=hbxq+ '<tr id="thisWL'+i+j+'">'+
                            '<input type="hidden"  id="ypwlType'+i+j+'" name="ypwlType'+i+j+'" value="1"/>'+
                            '<td>'+
                            '<div class="btn-group" style="border: 1px solid #ccc;border-radius: 6px;">'+
                            '<label class="btn btn-white" style="position: relative;">'+
                            '<input type="radio" class="wy" value="1" data-id="'+i+j+'" name="options" id="option" '+
                            'autocomplete="off" style="opacity: 0;position: absolute;">样品'+
                            '</label>'+
                            '<label class="btn btn-white active" style="position: relative;">'+
                            '<input type="radio" data-id="'+i+j+'" class="wy" value="0" name="options" id="option2" autocomplete="off" checked style="opacity: 0;position: absolute;"> 物料'+
                            '</label>'+
                            '</div>'+
                            '</td>'+
                            '<td style="display: none;" class="wlName" id="wlName'+i+j+'">'+
                            '<div class="input-group " id="select2wlName'+i+j+'"  style="display: inline-block;width: 63%"  >' +
                            '<input type="text" placeholder="请输入关键字或空格查询"  style="width: 100%"  onclick="yangpin('+i+j+')"  class="wlName'+i+j+'  form-control"  name="wlName'+i+j+'" value="">' +
                            '<div class="input-group-btn" style="top:25px">' +
                            '</button>' +
                            '<ul class="dropdown-menu dropdown-menu-right" role="menu">' +
                            '</ul>' +
                            '</div>' +
                            '</div>' +
                            '<div class="selectedOnlyOne" id="selectwlName'+i+j+'"  style="display: none;" >' +
                            '<span class="inin" style="width:200px"></span>' +
                            '<span class="closeX" style="cursor: pointer" onclick="closeX(\'wlName2'+i+j+'\')">×</span>' +
                            '</div>'
                            +
                            '</td>'+
                            '<td class="wlName2" id="wlName2'+i+j+'">'+
                            '<div class="input-group " id="select2wlName'+i+j+'"  style="display: inline-block;width: 63%"  >' +
                            '<input type="text" placeholder="请输入关键字或空格查询"  style="width: 100%" onclick="wuliao(2'+i+j+')"  class="wlName2'+i+j+'   form-control"  name="wlName2'+i+j+'" value="'+hb[j]['wlName']+'">' +
                            '<div class="input-group-btn" style="top:25px">' +
                            '</button>' +
                            '<ul class="dropdown-menu dropdown-menu-right" role="menu">' +
                            '</ul>' +
                            '</div>' +
                            '</div>' +
                            '<div class="selectedOnlyOne2" id="selectwlName'+i+j+'"  style="display: none;" >' +
                            '<span class="inin"></span>' +
                            '<span class="closeX" onclick="closeX(\'wlName'+i+j+'\')">×</span>' +
                            '</div>'+

                            '</td>'+
                            '<td><input type="text" class="form-control" id="wlnum'+i+j+'" name="wlnum'+i+j+'" value="'+hb[j]['num']+'" style="width: 80px" onblur="wlnum_to('+i+j+')" ></td>'+
                            '<td class="unit'+i+j+' units" id="unit'+i+j+'">'+hb[j]['unit']+'</td>'+
                            '<td class="factory'+i+j+' factorys2" id="factory'+i+j+'">'+hb[j]['factory']+'</td>'+
                            '<td class="allmoney'+i+j+' allmoneys" id="allmoney'+i+j+'">'+hb[j]['money']+'</td>'+
                            '<input type="hidden" class="allmoneys'+i+j+'" id="allmoneys'+i+j+'" name="all[]" value="'+hb[j]['money']+'"/>'+
                            '<td>'+
                            '<a class="btn btn-danger btn-bitbucket " onclick="del_this($(this),\'#thisWL'+i+j+'\')">'+
                            '<i class="fa fa-trash-o"></i> 删除'+
                            '</a>'+
                            '</td>'+
                            '</tr>';
                    }else {

                        var hbxq=hbxq+ '<tr id="thisWL'+i+j+'">'+
                            '<input type="hidden"  id="ypwlType'+i+j+'" name="ypwlType'+i+j+'" value="0"/>'+
                            '<td>'+
                            '<div class="btn-group" style="border: 1px solid #ccc;border-radius: 6px;">'+
                            '<label class="btn btn-white active" style="position: relative;">'+
                            '<input type="radio" class="wy" value="1" data-id="'+i+j+'" name="options" id="option" '+
                            'autocomplete="off" style="opacity: 0;position: absolute;">样品'+
                            '</label>'+
                            '<label class="btn btn-white" style="position: relative;">'+
                            '<input type="radio" data-id="'+i+j+'" class="wy" value="0" name="options" id="option2" autocomplete="off" checked style="opacity: 0;position: absolute;"> 物料'+
                            '</label>'+
                            '</div>'+
                            '</td>'+
                            '<td class="wlName" id="wlName'+i+j+'">'+
                            '<div class="input-group " id="select2wlName'+i+j+'"  style="display: inline-block;width: 63%"  >' +
                            '<input type="text" placeholder="请输入关键字或空格查询"  style="width: 100%"  onclick="yangpin('+i+j+')"  class="wlName'+i+j+'  form-control"  name="wlName'+i+j+'" value="'+hb[j]['wlName']+'">' +
                            '<div class="input-group-btn" style="top:25px">' +
                            '</button>' +
                            '<ul class="dropdown-menu dropdown-menu-right" role="menu">' +
                            '</ul>' +
                            '</div>' +
                            '</div>' +
                            '<div class="selectedOnlyOne" id="selectwlName'+i+j+'"  style="display: none;" >' +
                            '<span class="inin" style="width:200px"></span>' +
                            '<span class="closeX" style="cursor: pointer" onclick="closeX(\'wlName'+i+j+'\')">×</span>' +
                            '</div>'
                            +
                            '</td>'+
                            '<td style="display: none;"  class="wlName2" id="wlName2'+i+j+'">'+
                            '<div class="input-group " id="select2wlName'+i+j+'"  style="display: inline-block;width: 63%"  >' +
                            '<input type="text" placeholder="请输入关键字或空格查询"  style="width: 100%" onclick="wuliao(2'+i+j+')"  class="wlName2'+i+j+'   form-control"  name="wlName2'+i+j+'" value="">' +
                            '<div class="input-group-btn" style="top:25px">' +
                            '</button>' +
                            '<ul class="dropdown-menu dropdown-menu-right" role="menu">' +
                            '</ul>' +
                            '</div>' +
                            '</div>' +
                            '<div class="selectedOnlyOne2" id="selectwlName'+i+j+'"  style="display: none;" >' +
                            '<span class="inin"></span>' +
                            '<span class="closeX" onclick="closeX(\'wlName2'+i+j+'\')">×</span>' +
                            '</div>'+
                            '</td>'+
                            '<td><input type="text" class="form-control" id="wlnum'+i+j+'" name="wlnum'+i+j+'" value="'+hb[j]['num']+'" style="width: 80px" onblur="wlnum_to('+i+j+')" ></td>'+
                            '<td class="unit'+i+j+' units" id="unit'+i+j+'">'+hb[j]['unit']+'</td>'+
                            '<td class="factory'+i+j+' factorys2" id="factory'+i+j+'">'+hb[j]['factory']+'</td>'+
                            '<td class="allmoney'+i+j+' allmoneys" id="allmoney'+i+j+'">'+hb[j]['money']+'</td>'+
                            '<input type="hidden" class="allmoneys'+i+j+'" id="allmoneys'+i+j+'" name="all[]" value="'+hb[j]['money']+'"/>'+
                            '<td>'+
                            '<a class="btn btn-danger btn-bitbucket " onclick="del_this($(this),\'#thisWL'+i+j+'\')">'+
                            '<i class="fa fa-trash-o"></i> 删除'+
                            '</a>'+
                            '</td>'+
                            '</tr>';
                    }
// +j+  +i+j+
                }
            }


            var fyxq = ' <tr  id="FeiYongLeiXingList'+i+'">\n' +
                '                    <td   id="feetype{#id}" >\n' +
                '\n' +
                '                    </td>\n' +
                '                    <td>\n' +
                '                        <select name="status[]" id="state{#id}" data-id="'+data[i]['paymethod']+'"  onchange="gradeChange({#id})" class="form-control select feetype" style="min-width: 100px;width: 100px;padding: 2px 10px;">\n' +
                '                            <option id="isNull{#id}" value="0">请选择</option>\n' +
                '                        </select>\n' +
                '                    </td>\n' +
                '                    <td>\n' +
                '                       <div class="input-group">\n' +
                '                        <input type="text" class="form-control fRmb" id="fRmb{#id}" name="fRmb[]" value="'+data[i]['hanshuis']+'" onchange="fRmbchange()" aria-label="RMB" style="width: 60px;height: 30px">\n' +
                '                        <input type="hidden" value="'+data[i]['hb']+'" id="hbxx{#id}" name="hbxx{#id}" >\n' +
                '                         <span class="input-group-addon">元</span>\n' +
                '                         \n' +
                '                        </div>\n' +
                '                        <a href="" data-toggle="modal" id="xgcbzx{#id}" data-target="" style="display:none;">\n' +                   //style="display:none;"  id="xgcbzx{#id}"  addyw
                '                        <span class="fa fa-eyedropper"  style="cursor: pointer;" data-toggle="tooltip" data-placement="right" title="修改样品物料"></span></a>\n' +
                '<div class="modal fade" tabindex="-1" role="dialog" id="myModal1{#id}" aria-labelledby="gridSystemModalLabel">\n' +
                '  <div class="modal-dialog  modal-lg" role="document">\n' +
                '    <div class="modal-content">\n' +
                '      <div class="modal-header">\n' +
                '        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="font-size: 16px">&times;</span></button>\n' +
                '        <h2 class="modal-title" id="SystemModalLabel">样品物料</h2>\n' +
                '      </div>\n' +
                '     \n' +
                '      <div class="modal-body" style="position: relative;min-height: 400px;height: auto;">\n' +
                '                <form action="" class="form-inline"   id="YpWlform{#id}">\n' +
                '         <table class="table-bordered table-hover table text-center" id="ywTable{#id}">\n' +
                '            <thead>\n' +
                '                <tr class="info">\n' +
                '                    <th class="text-center">类型</th>\n' +
                '                    <th class="text-center">样品/物料</th>\n' +
                '                    <th class="text-center">数量</th>\n' +
                '                    <th class="text-center">单位</th>\n' +
                '                    <th class="text-center">单价</th>\n' +
                '                    <th class="text-center">金额(元)</th>\n' +
                '                    <th class="text-center"><button class="btn btn-success" id="addyw{#id}" type="button" onclick=""><i class="fa fa-plus-square"></i>&nbsp;&nbsp;<span class="bold">添加</span>\n' +
                '                        </button></th>\n' +
                '                </tr>\n' +
                '            </thead>\n' +

                '            <tbody id="YpWl{#id}">\n' +
                hbxq+
                '            </tbody>\n' +

                '         </table>\n' +
                '                </form>\n' +
                '    </div>\n' +
                '    <div class="modal-footer">\n' +
                '        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>\n' +
                '        <button type="button" class="btn btn-primary" onclick="tijiao2({#id})">保存</button>\n' +
                '         \n' +
                '      </div>\n' +
                '    </div><!-- /.modal-content -->\n' +
                '  </div><!-- /.modal-dialog -->\n' +
                '</div>' +
                '                    </td>\n' +
                '                    <td>\n' +
                '                        <div class="btn-group" id="is_shoukuanF{#id}">\n' +
                '\n' +
                '                        </div><br><br>\n' +
                '                        <div id="payee{#id}">\n' +
                '\n' +
                '                        </div>\n' +
                '\n' +
                '                    </td>\n' +
                '\n' +
                '                    <td>\n' +
                '                        <div class="form-group" style="width: 60%" id="showSelectText{#id}">\n' +
                '                            <p><span >'+data[i]['cbinfo']+'</span>，100%</p>\n' +
                '                            <input name="cbzx{#id}" value="'+data[i]['cbinfo']+'" type="hidden">\n' +
                '                        </div><a href="javascript:;" data-toggle="modal" data-target="#myModal{#id}" style="line-height: 1;display: inline-block;vertical-align: bottom;">\n' +
                '                        <span class="fa fa-eyedropper" style="cursor: pointer;vertical-align: bottom;margin-bottom: 8px" data-toggle="tooltip" data-placement="right" title="修改成本中心"></span></a>\n' +
                '<div class="modal fade" tabindex="-1" role="dialog" id="myModal{#id}" aria-labelledby="gridSystemModalLabel">\n' +
                '            <div class="modal-dialog" role="document">\n' +
                '                <div class="modal-content">\n' +
                '                    <div class="modal-header">\n' +
                '                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="font-size: 16px">&times;</span></button>\n' +
                '                        <h2 class="modal-title" id="gridSystemModalLabel">成本中心</h2>\n' +
                '                    </div>\n' +
                '\n' +
                '                    <div class="modal-body" style="position: relative;min-height: 400px;height: auto;">\n' +
                '                        <div class="control-group" >\n' +
                '\n' +
                '\n' +
                '\n' +
                '                            <select class="selectpicker show-menu-arrow" id="multiples{#id}" style="width:100% ">\n' +
                '\n' +
                '                            </select>\n' +
                '\n' +
                '                            <div class="padding-10" id="selectDiv{#id}">\n' +
                '                            </div>\n' +
                '                            <p class="alert alert-warning" style="position: absolute;bottom: 0;left: 5px;padding: 5px;width: 95%;box-sizing: border-box;">\n' +
                '                                占比加起来必须等于100%\n' +
                '                            </p>\n' +
                '                        </div>\n' +
                '                    </div>\n' +
                '                    <div class="modal-footer">\n' +
                '                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>\n' +
                '                        <button type="button" onclick="tijiao({#id})" id class="btn btn-primary">保存</button>\n' +
                '\n' +
                '                    </div>\n' +
                '                </div><!-- /.modal-content -->\n' +
                '            </div><!-- /.modal-dialog -->\n' +
                '</div>'+
                '</td>\n' +
                '                    <td>' +
                '<input type="text" class="form-control"  name="fbreif[]" value="'+data[i]['feiyongmiaoshu']+'" style="width: 100%" placeholder="简要说明费用构成">' +
                '<div>' +
                '<div id="cl_type{#id}"  style="display:none;" data-id="'+data[i]['cl_type']+'" ></div>' +
                '<div id="cl_place{#id}"  style="display:none;" data-id="'+data[i]['cl_place']+'"></div>' +
                '<div id="cl_size{#id}"  style="display:none;" data-id="'+data[i]['cl_size']+'"></div>' +
                '</div>' +
                '</td>\n' +
                '                    <td>\n' +
                '                        <a class="btn btn-white btn-bitbucket">\n' +
                '                            <i class="fa fa-trash-o"></i> 删除\n' +
                '                        </a>\n' +

                '                   </td>\n' +


                '                </tr>';

            //uploadTr(fyxq,'#FeiYongLeiXingList','',a,title,i);// feiyongxiagqing fyxq

            //uploadTr(fyxq,'#FeiYongLeiXingList','',a,title,i);
            uploadTr3(fyxq,'#FeiYongLeiXingList','',a,title,i,2);




        }

        for(var i=0;i<data.length;i++){
//费用类型  active  active
            $("#FeiYongLeiXingList>tr").each(function(){
                $(this).find(".input-group ").eq(0).closest('.input-group').hide();
            })
            $("#FeiYongLeiXingList"+i).find(".inin ").eq(0).html(data[i]['title']);
            $("#FeiYongLeiXingList"+i).find(".selectedOnlyOne ").eq(0).css("display", "inline");
            var Td = $("#FeiYongLeiXingList"+i).find('td').eq(0).attr("ID");
            console.log(Td,'TdTd')
            var skf =Td.replace('feetype','is_shoukuanF');
            var id = Td.replace('feetype','');;
            if(data[i]['payeetype']==1){ //经销商
                $('#'+skf).find("label").eq(0).addClass('active');
                $('#'+skf).find("label").eq(1).removeClass('active');
                $('input[name=payee'+id+']').val('-1');//当值为-1时，选取的为经销商，并且经销商的值通过jxs_id获取
                $("#payee"+id).hide();
            }else {   //供应商
                $('#'+skf).find("label").eq(1).addClass('active');
                $('#'+skf).find("label").eq(0).removeClass('active');
                $("#select2payee"+id).hide();
                $("#selectpayee"+id).show();
                $('input[name=payee'+id+']').val(data[i]['payee']);
                $("#selectpayee"+id).find(".inin ").eq(0).html(data[i]['payeename']);
            }
            if(data[i]['cl_type']!=null){
                $("#select2cl_type"+id).hide();//select2cl_type
                $("#selectcl_type"+id).show(); //selectcl_type
                $('input[name=cl_type'+id+']').val(data[i]['cl_type']);
                $("#selectcl_type"+id).find(".inin ").eq(0).html(data[i]['cl_typename']);
            }
            if(data[i]['cl_place']!=null){
                $("#select2cl_place"+id).hide();//select2cl_type
                $("#selectcl_place"+id).show(); //selectcl_type
                $('input[name=cl_place'+id+']').val(data[i]['cl_place']);
                $("#selectcl_place"+id).find(".inin ").eq(0).html(data[i]['cl_placename']);
            }
            console.log(data[i],'cl_size');
            if(data[i]['cl_size']!=null){
                $("#select2cl_size"+id).hide();//select2cl_type
                $("#selectcl_size"+id).show(); //selectcl_type
                $('input[name=cl_size'+id+']').val(data[i]['cl_size']);
                $("#selectcl_size"+id).find(".inin ").eq(0).html(data[i]['cl_sizename']);
            }
            var cp_id=data[i]['feetype'];
            $("#FeiYongLeiXingList").find('input[name="' +Td +'"]').val(cp_id);
            if(data[i]['method']==1){
               // $('#myModal1'+id).modal('show');
                $('#xgcbzx'+id).show();
            }
            var hb=data[i]['hbinfo'];
            console.log(data,'data')
            var hbtype=data[i]['hbtype'];
            /*if(hbtype==1){
                var hbxq = '';
                for(var j=0;j<hb.length;j++){
                    if(data[i]['cl_size']!=''){
                        $("#select2cl_size"+id).hide();//select2cl_type
                        $("#selectcl_size"+id).show(); //selectcl_type
                        $('input[name=cl_size'+id+']').val(data[i]['cl_size']);
                        $("#selectcl_size"+id).find(".inin ").eq(0).html(data[i]['cl_sizename']);
                    }
                }
            }*/
            if(hbtype==1){  //有货补数据

//                cars=["BMW","Volvo","Saab","Ford"];
//                for (var i=0;i<cars.length;i++)
//                {
//                    console.log(i,'i1')
//                    console.log(cars[i] + "<br>");
//                }


                var j=0;
                console.log(j,'je')
                for(var j=0;j<hb.length;j++){
                    console.log(j,'j1')
                    console.log(hb,'hb')
                    if(hb[j]['wlyptype']==1){ //物料 wlName2
                        var ids=parseFloat(id+j);

//                        $(this).val(data.id);
//                        $(this).closest('.input-group').hide();
//                        $(this).closest('.input-group').hide();
//                        $(this).val(data.id);
//                        $(this).closest('.input-group').hide();
//                        $(this).closest('.input-group').hide();

//                        $('#select'+ids).show().find('.inin').html(data[j]['wlName']);
                        console.log(data,'data')
                        console.log(j,'j')
                        $("#selectwlName"+id).find(".inin ").eq(0).html(hb[j]['wlName']);
                        $("#selectwlName2"+id).find(".inin ").eq(0).html(hb[j]['wlName']);
                        $("#thisWL"+ids)
                        $("#thisWL"+ids).val(data.id);
                        $("#thisWL"+ids).closest('.input-group').hide();
                        $("#thisWL"+ids).closest('.input-group').hide();
                        $('#select'+ids).show().find('.inin').html(data.key);
                        //var rs = $('#thisWL'+id).attr('rs2');
                        /*$("#select2wlName2"+id).hide();//select2cl_type
                        $("#selectcl_size"+id).show(); //selectcl_type
                        $('input[name=wlName2'+id+']').val(data[j]['wlName']);
                        $("#selectwlName2"+id).find(".inin ").eq(0).html(data[j]['wlName']);*/
                    }else { //样品
                        var ids=parseFloat(id+j);
                        //$('#select'+ids).show().find('.inin').html(data[j]['wlName']);
                        /*$("#select2wlName"+id).hide();//select2cl_type
                        $("#selectwlName"+id).show(); //selectcl_type
                        $('input[name=wlName'+id+']').val(data[j]['wlName']);
                        $("#selectwlName"+id).find(".inin ").eq(0).html(data[j]['wlName']);*/
//                        $("#selectwlName"+id).find(".inin ").eq(0).html(data[j]['wlName']);
//                        $("#selectwlName2"+id).find(".inin ").eq(0).html(data[j]['wlName']);
                        console.log(j,'j2')
                    }
                }
            }
        }



        //客户详情
        var kh_type="{$apply['khtype']}";
        /*console.log(kh_type);
        console.log('kh_type');*/
        switch (kh_type) {
            case "1":
                $("#is_kehuxiangqing").find('label').eq(2).removeClass('active')
                $("#is_kehuxiangqing").find('label').eq(1).removeClass('active')
                $("#is_kehuxiangqing").find('label').eq(0).addClass('active')
                $("#angencyTable").show();
                $("#sysTable").hide();
                $("#netTable").hide();
                $(".netlist").remove();
                $("#JinXiaoShangZhu").empty();
                $("#khxqtype").val('1');

                break;
            case "2":
                var data = JSON.parse('{$khxt}');
                console.log(data,'data')

                for(var i=0;i<data.length;i++){
                    console.log(i,'i')
                    var khxt = '<tr class="text-center JinXiaoShang'+i+'">\n' +
                        '                    <td>\n' +
                        '                        <div class="input-group form-group" id="JinXiaoShang{#id}" style="display: inline-block;" id="selectDivangency1">\n' +
                        '\n' +
                        '\n' +
                        '                        </div>\n' +
                        '                    </td>\n' +
                        '                    <td> \n' +
                        '                         <div class="input-group">\n' +
                        '                        <input type="text" class="form-control JinXiaoShangBl" id="JinXiaoShangBl{#id}" value="'+data[i]['xt_zb']+'" name="JinXiaoShangBl{#id}" aria-label="" style="width: 60px;height: 30px">\n' +
                        '                         <span class="input-group-addon">%</span>\n' +
                        '                        </div>   \n' +
                        '                    </td>\n' +
                        '                     <td> \n' +
                        '                         <div class="input-group">\n' +
                        '                        <input type="text" class="form-control JinXiaoShangNum" id="JinXiaoShangNum{#id}" value="'+data[i]['net_num']+'" name="JinXiaoShangNum{#id}" aria-label="" style="width: 60px;height: 30px">\n' +
                        '                         <span class="input-group-addon">家</span>\n' +
                        '                        </div>   \n' +
                        '                    </td>\n' +
                        '                    <td>\n' +
                        '                         <a class="btn btn-white btn-bitbucket">\n' +
                        '                            <i class="fa fa-trash-o"></i> 删除\n' +
                        '                        </a>\n' +
                        '                    </td>\n' +
                        '                </tr>';
                    uploadTr(khxt,'#JinXiaoShangZhu','',b,'',i);
                }

                for(var i=0;i<data.length;i++){
                    $("#JinXiaoShangZhu>tr").each(function(){
                        $(this).find(".input-group ").eq(0).closest('.input-group').hide();
                    })
                    $("#JinXiaoShangZhu").find(".inin ").eq(i).html(data[i]['title']);
                    $("#JinXiaoShangZhu").find(".selectedOnlyOne ").eq(i).css("display", "inline");
                    var Td = $("#JinXiaoShangZhu").find('tr').eq(i).find('div').eq(0).attr("ID");  //此处获取的是div,而不是td
                    var num =Td.replace("JinXiaoShang", "select2JinXiaoShang");
                    $("#"+num).css("display", "none");
                    var cp_id=data[i]['xt_id'];
                    $("#"+Td).attr("display", "inline");
                    $("#JinXiaoShangZhu").find('input[name="' +Td +'"]').val(cp_id);
                    $("#JinXiaoShangZhu").find('tr').eq(i).find('div').eq(0).css("display", "inline")
                }
                $("#JinXiaoShangZhu").find('tr').each(function(){ //block
                    $(this).find('div').eq(0).css("display", "block")
                })
                break;
            case "3":

                $("#is_kehuxiangqing").find('label').eq(0).removeClass('active')
                $("#is_kehuxiangqing").find('label').eq(1).removeClass('active')
                $("#is_kehuxiangqing").find('label').eq(2).addClass('active')
                $("#angencyTable").hide();
                $("#sysTable").hide();
                $("#netTable").show();
                $("#JinXiaoShangZhu").empty();
                $("#khxqtype").val('3');
                var data = JSON.parse('{$khnet}');
                for(var i=0;i<data.length;i++){
                    $('#selected_net').append('<span class="ren netlist" data-id="'+data[i]['net_id']+'">'+data[i]['title']+'<span class="close">×</span></span>')
                }
                break;
        }


        //产品详情
        var cp_type="{$apply['cp_type']}";

        var fylx="{$fylx}";
        if(fylx==2){
            showTable($(this),42);
        }else if (fylx==4){
            showTable($(this),44);
        }else if (fylx==7){
            showTable($(this),43);
        }


        $('#is_changpingxiangqin').find("label").removeClass('active')

        switch (cp_type) {
            case "0":
                $('#is_changpingxiangqin').find("label").eq(0).addClass('active')

                var data = JSON.parse('{$cp_name}');
                for(var i=0;i<data.length;i++){

                    var cpxq0 = '<tr class="text-center">\n' +
                        '                <td id="proTableInput0{#id}">\n' +
                        '\n' +
                        '                </td>\n' +
                        '\n' +
                        '                <td>\n' +
                        '                    <div class="input-group">\n' +
                        '                        <input type="text" class="form-control" name="proTableInputBl0{#id}" value="'+data[i]['cp_zb']+'" id="proTableInputBl0{#id}" aria-label="" style="width: 60px;height: 30px">\n' +
                        '                        <span class="input-group-addon">%</span>\n' +
                        '                    </div>\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <input type="text" class="form-control" name="proTableInputSm0{#id}" value="'+data[i]['cp_sm']+'" id="proTableInputSm0{#id}" placeholder="简要说明产品">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <a class="btn btn-white btn-bitbucket">\n' +
                        '                        <i class="fa fa-trash-o"></i> 删除\n' +
                        '                    </a>\n' +
                        '                </td>\n' +
                        '            </tr>';
                    uploadTr(cpxq0,'#Cpxq0','',c,'',i);

                }

                for(var i=0;i<data.length;i++){

                    $("#Cpxq0>tr").each(function(){
                        $(this).find(".input-group ").eq(0).closest('.input-group').hide();
                    })

                    $("#Cpxq0").find(".inin ").eq(i).html(data[i]['name']);

                    $("#Cpxq0").find(".selectedOnlyOne ").eq(i).css("display", "inline");
                    var Td = $("#Cpxq0").find('tr').eq(i).find('td').eq(0).attr("ID");
                    var cp_id=data[i]['id'];

                    $("#Cpxq0").find('input[name="' +Td +'"]').val(cp_id);

                }
                break;
            case "1":
                $('#is_changpingxiangqin').find("label").eq(1).addClass('active')

                var data = JSON.parse('{$cp_name}');
                for(var i=0;i<data.length;i++){

                    var cpxq1 = '<tr class="text-center">\n' +
                        '                <td id="proTableInput1{#id}">\n' +
                        '\n' +
                        '                </td>\n' +
                        '\n' +
                        '                <td>\n' +
                        '                    <div class="input-group">\n' +
                        '                        <input type="text" class="form-control" name="proTableInputBl1{#id}" value="'+data[i]['cp_zb']+'" id="proTableInputBl1{#id}" aria-label="" style="width: 60px;height: 30px">\n' +
                        '                        <span class="input-group-addon">%</span>\n' +
                        '                    </div>\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <input type="text" class="form-control" name="proTableInputSm1{#id}" value="'+data[i]['cp_sm']+'" id="proTableInputSm1{#id}" placeholder="简要说明产品">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <a class="btn btn-white btn-bitbucket">\n' +
                        '                        <i class="fa fa-trash-o"></i> 删除\n' +
                        '                    </a>\n' +
                        '                </td>\n' +
                        '            </tr>';
                    uploadTr(cpxq1,'#Cpxq1','',d,'',i);

                }

                for(var i=0;i<data.length;i++){

                    $("#Cpxq1>tr").each(function(){
                        $(this).find(".input-group ").eq(0).closest('.input-group').hide();
                    })

                    $("#Cpxq1").find(".inin ").eq(i).html(data[i]['name']);

                    $("#Cpxq1").find(".selectedOnlyOne ").eq(i).css("display", "inline");
                    var Td = $("#Cpxq1").find('tr').eq(i).find('td').eq(0).attr("ID");
                    var cp_id=data[i]['id'];

                    $("#Cpxq1").find('input[name="' +Td +'"]').val(cp_id);

                }
                break;
            case "2":
                $('#is_changpingxiangqin').find("label").eq(2).addClass('active')
                //keyi   proTableInput2 是系列
                var data = JSON.parse('{$cp_name}');
                for(var i=0;i<data.length;i++){

                    var cpxq3 = '<tr class="text-center">\n' +
                        '                <td id="proTableInput2{#id}">\n' +
                        '\n' +
                        '                </td>\n' +
                        '\n' +
                        '                <td>\n' +
                        '                    <div class="input-group">\n' +
                        '                        <input type="text" class="form-control" name="proTableInputBl2{#id}" value="'+data[i]['cp_zb']+'" id="proTableInputBl2{#id}" aria-label="" style="width: 60px;height: 30px">\n' +
                        '                        <span class="input-group-addon">%</span>\n' +
                        '                    </div>\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <input type="text" class="form-control" name="proTableInputSm2{#id}" value="'+data[i]['cp_sm']+'" id="proTableInputSm2{#id}" placeholder="简要说明产品">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <a class="btn btn-white btn-bitbucket">\n' +
                        '                        <i class="fa fa-trash-o"></i> 删除\n' +
                        '                    </a>\n' +
                        '                </td>\n' +
                        '            </tr>';

                    uploadTr(cpxq3,'#Cpxq2','',e,'',i);

                }

                for(var i=0;i<data.length;i++){

                    $("#Cpxq2>tr").each(function(){
                        $(this).find(".input-group ").eq(0).closest('.input-group').hide();
                    })

                    $("#Cpxq2").find(".inin ").eq(i).html(data[i]['name']);

                    $("#Cpxq2").find(".selectedOnlyOne ").eq(i).css("display", "inline");
                    var Td = $("#Cpxq2").find('tr').eq(i).find('td').eq(0).attr("ID");
                    var cp_id=data[i]['id'];

                    $("#Cpxq2").find('input[name="' +Td +'"]').val(cp_id);

                }
                break;
            case "3":
                $('#is_changpingxiangqin').find("label").eq(3).addClass('active')
                var data = JSON.parse('{$cp_name}');
                for(var i=0;i<data.length;i++){

                    var cpxq4 = '<tr class="text-center">\n' +
                        '                <td id="proTableInput3{#id}">\n' +
                        '\n' +
                        '                </td>\n' +
                        '\n' +
                        '                <td>\n' +
                        '                    <div class="input-group">\n' +
                        '                        <input type="text" class="form-control" name="proTableInputBl3{#id}" value="'+data[i]['cp_zb']+'" id="proTableInputBl3{#id}" aria-label="" style="width: 60px;height: 30px">\n' +
                        '                        <span class="input-group-addon">%</span>\n' +
                        '                    </div>\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <input type="text" class="form-control" name="proTableInputSm3{#id}" value="'+data[i]['cp_sm']+'" id="proTableInputSm3{#id}" placeholder="简要说明产品">\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <a class="btn btn-white btn-bitbucket">\n' +
                        '                        <i class="fa fa-trash-o"></i> 删除\n' +
                        '                    </a>\n' +
                        '                </td>\n' +
                        '            </tr>';

                    uploadTr(cpxq4,'#Cpxq3','',f,'',i);

                }

                for(var i=0;i<data.length;i++){

                    $("#Cpxq3>tr").each(function(){
                        $(this).find(".input-group ").eq(0).closest('.input-group').hide();
                    })

                    $("#Cpxq3").find(".inin ").eq(i).html(data[i]['name']);

                    $("#Cpxq3").find(".selectedOnlyOne ").eq(i).css("display", "inline");
                    var Td = $("#Cpxq3").find('tr').eq(i).find('td').eq(0).attr("ID");
                    var cp_id=data[i]['id'];

                    $("#Cpxq3").find('input[name="' +Td +'"]').val(cp_id);

                }
                break;
            case "4":

                $('#is_changpingxiangqin').find("label").eq(4).addClass('active')
                var data = JSON.parse('{$cp_name}');
                for(var i=0;i<data.length;i++){
                    if(data[i]['fylx']==2){
                        //随货折扣类 单品
                        var changpingxianqin6='<tr class="text-center" >\n' +
                            '                    <td id="proTableInput4{#id}">\n' +
                            '                    </td>\n' +
                            '                    <td style="text-align: center;" class="num{#id}">\n' +
                            '                        <input type="text" class="form-control" value="'+data[i].boxnum+'" name="num{#id}" id="num{#id}" placeholder="">每箱' +data[i].box_num+data[i].unit  +
                            '                    </td>\n' +
                            '                    <td class="shzkldp{#id}" id="shzkldp{#id}">\n' +
                            '                        <div>\n' +
                            '                            <div class="" style="text-align: left;" class="oldprice{#id}">\n' +
                            '                                原供价:<input type="text" autocomplete="off"  disabled="disabled" value="'+data[i].yuan_price+'" id="oldprice{#id}" name="oldprice{#id}" style="width: 60px;">元 / 箱\n' +
                            '                            </div>\n' +
                            '                            <br>\n' +
                            '                            <div class="" style="text-align: left;"  class="nowprice{#id}">\n' +
                            '                                现供价:\n' +
                            '                                <input type="text" autocomplete="off" value="'+data[i].now_price+'" id="nowprice{#id}" name="nowprice{#id}" onblur="nowprice_change({#id});" style="width: 60px;" class="el-input__inner">元 / 箱\n' +
                            '                                <input type="hidden"  id="nowprice2{#id}" name="nowprice2{#id}" value="'+data[i].xtxgj+'" >' +
                            '                            </div>\n' +
                            '                            <br>\n' +
                            '                            <div class="" style="text-align: left;" class="dealerZheJiaLv{#id}">\n' +
                            '                                折价率:\n' +
                            '                                <input type="text" autocomplete="off" value="'+data[i].zhejia+'" id="dealerZheJiaLv{#id}" name="dealerZheJiaLv{#id}" onblur="ZheJiaLv_change({#id});" style="width: 60px;" class="el-input__inner">% OFF\n' +
                            '                            </div>\n' +
                            '\n' +
                            '                            <br> <div style="text-align: left; font-size: 12px; color: rgb(102, 102, 102); font-style: italic;">\n' +
                            '                            顺加'+data[i].sj+'% 倒扣'+data[i].dk+'%\n' +
                            '<a class="hover" href="#">\n' +
                            '                                <span>帮助</span>\n' +
                            '                                <div class="ex" style="width: 400px;height: 100px;">经销商的顺加毛利率 =（网点现供价 - 经销商现供价）/ 经销商现供价\n' +
                            '                                    <br>\n' +
                            '                                    经销商的倒扣毛利率 = （网点现供价 - 经销商现供价）/ 网点现供价</div>\n' +
                            '                            </a>' +
                            '\t\t</span>\n' +
                            '\t\t</span>\n' +
                            '                        </div>\n' +
                            '                        </div>\n' +
                            '                    </td>\n' +
                            '                    <td>\n' +
                            '                        <input type="text" class="form-control" value="'+data[i].cp_sm+'" name="proTableInputSm4{#id}" id="proTableInputSm4{#id}" placeholder="简要说明产品">\n' +
                            '                    </td>\n' +
                            '                    <td>\n' +
                            '                     <a class="btn btn-white btn-bitbucket">\n' +
                            '                            <i class="fa fa-trash-o"></i> 删除\n' +
                            '                        </a>\n' +
                            '                    </td>\n' +
                            '                </tr>';

                        var cpxq5 = changpingxianqin6;


                        /*var cpxq5 = '<tr class="text-center">\n' +
                            '                <td id="proTableInput4{#id}">\n' +
                            '\n' +
                            '                </td>\n' +
                            '\n' +
                            '                <td>\n' +
                            '                    <div class="input-group">\n' +
                            '                        <input type="text" class="form-control" name="proTableInputBl4{#id}" value="'+data[i]['cp_zb']+'" id="proTableInputBl4{#id}" aria-label="" style="width: 60px;height: 30px">\n' +
                            '                        <span class="input-group-addon">%</span>\n' +
                            '                    </div>\n' +
                            '                </td>\n' +
                            '                <td>\n' +
                            '                    <input type="text" class="form-control" name="proTableInputSm4{#id}" value="'+data[i]['cp_sm']+'" id="proTableInputSm4{#id}" placeholder="简要说明产品">\n' +
                            '                </td>\n' +
                            '                <td>\n' +
                            '                    <a class="btn btn-white btn-bitbucket">\n' +
                            '                        <i class="fa fa-trash-o"></i> 删除\n' +
                            '                    </a>\n' +
                            '                </td>\n' +
                            '            </tr>';*/

                        // uploadTr(cpxq5,'#Cpxq4','',g,'',i);
                        //uploadTr(cpxq5,'#Cpxq42','',g2,'',i);
                        uploadTr(cpxq5,'#Cpxq42','',g2,'',i);


                    }else if(data[i]['fylx']==4){
                        var changpingxianqin8='<tr class="text-center" >\n' +
                            '                    <td id="proTableInput4{#id}">\n' +
                            '                    </td>\n' +
                            '                    <td style="text-align: center;" class="num{#id}">\n' +
                            '                         <div class="input-group">\n' +
                            '                        <input type="text" class="form-control pro_num" value="'+data[i].boxnum+'" name="num{#id}" id="num{#id}" style="width: 60px;"> 箱 <br><br>  '+'每箱'+data[i].box_num+data[i].unit +
                            '                        </div>   \n' +
                            '                    </td>\n' +
                            '                    <td  style="text-align: center;" class="shzkldp{#id}" id="shzkldp{#id}">\n' +
                            '                        <div>\n' +
                            '                            <div class="" style="text-align: left;" class="oldprice{#id}">\n' +
                            '                                <input type="hidden" name="oldprices{#id}" value="'+data[i].yuan_price+'" >' +    /*有何用，后期了解，必须的*/
                            '                                原供价:<input type="text" autocomplete="off" class="jxs_yuan"  disabled="disabled" value="'+data[i].yuan_price+'" id="oldprice{#id}" name="oldprice{#id}" style="width: 60px;">元 / 箱\n' +
                            '                            </div>\n' +
                            '                            <br>\n' +
                            '                            <div class="" style="text-align: left;"  class="nowprice{#id}">\n' +
                            '                                现供价:\n' +
                            '                                <input type="text" autocomplete="off" class="jxs_now" value="'+data[i].now_price+'" onblur="nowprice_change({#id});" id="nowprice{#id}" name="nowprice{#id}" style="width: 60px;" class="el-input__inner">元 / 箱\n' +
                            '                            </div>\n' +
                            '                            <br>\n' +
                            '                            <div class="" style="text-align: left;" class="dealerZheJiaLv{#id}">\n' +
                            '                                折价率:\n' +
                            '                                <input type="text" autocomplete="off" class="jxs_zhe" value="'+data[i].zhejia+'" id="dealerZheJiaLv{#id}" onblur="ZheJiaLv_change({#id});" name="dealerZheJiaLv{#id}" style="width: 60px;" class="el-input__inner">% OFF\n' +
                            '                            </div>\n' +
                            '\n' +
                            '                            <br> <div style="text-align: left; font-size: 12px; color: rgb(102, 102, 102); font-style: italic;" class="jxs_mao">\n' +
                            '                            <span>顺加'+data[i].sj+'% 倒扣'+data[i].dk+'%</span>\n' +
                            '<a class="hover" href="#">\n' +
                            '                                <span>帮助</span>\n' +
                            '                                <div class="ex" style="width: 400px;height: 100px;">经销商的顺加毛利率 =（网点现供价 - 经销商现供价）/ 经销商现供价' +
                            '                                    <br>' +
                            '                                    经销商的倒扣毛利率 = （网点现供价 - 经销商现供价）/ 网点现供价</div>' +
                            '                            </a>' +
                            '\t\t</span>\n' +
                            '\t\t</span>\n' +
                            '                        </div>\n' +
                            '                        </div>\n' +
                            '                    </td>\n' +
                            '                    <td style="text-align: center;" class="shzkldp2{#id}" id="shzkldp2{#id}">\n' +
                            '                        <div>\n' +
                            '                            <div class="" style="text-align: left;" class="oldprice2{#id}">\n' +
                            '                                <input type="hidden" name="oldprices2{#id}" value="'+data[i].wangdian_yuan+'" >' +
                            '                                原供价:<input type="text" autocomplete="off" class="net_yuan" value="'+data[i].wangdian_yuan+'"  id="oldprice2{#id}" name="oldprice2{#id}" style="width: 60px;">元 / 箱\n' +
                            '                            </div>\n' +
                            '                            <br>\n' +
                            '                            <div class="" style="text-align: left;"  class="nowprice2{#id}">\n' +
                            '                                现供价:\n' +
                            '                                <input type="text" autocomplete="off" class="net_now" value="'+data[i].wangdian_price+'" id="nowprice2{#id}" name="nowprice2{#id}" onblur="nowprice_change2({#id});" style="width: 60px;" class="el-input__inner">元 / 箱\n' +
                            '                            </div>\n' +
                            '                            <br>\n' +
                            '                            <div class="" style="text-align: left;" class="dealerZheJiaLv2{#id}">\n' +
                            '                                折价率:\n' +
                            '                                <input type="text" autocomplete="off" class="net_zhe" value="'+data[i].wangdian_zhejia+'" onblur="ZheJiaLv_change2({#id});" id="dealerZheJiaLv2{#id}" name="dealerZheJiaLv2{#id}" style="width: 60px;" class="el-input__inner">% OFF\n' +
                            '                            </div>\n' +
                            '\n' +
                            '                            <br> <div style="text-align: left; font-size: 12px; color: rgb(102, 102, 102); font-style: italic;" class="net_mao">\n' +
                            '                            <span>顺加'+ data[i].sj2 +'% 倒扣'+ data[i].dk2 +'%</span>\n' +
                            '<a class="hover" href="#">\n' +
                            '                                <span>帮助</span>\n' +
                            '                                <div class="ex" style="width: 400px;height: 100px;">网点的顺加毛利率 = （活动期零售价 - 网点现供价）/ 网点现供价' +
                            '                                    <br>' +
                            '                                    网点的倒扣毛利率 = （活动期零售价 - 网点现供价）/ 活动期零售价</div>' +
                            '                            </a>' +
                            '\t\t</span>\n' +
                            '\t\t</span>\n' +
                            '                        </div>\n' +
                            '                        </div>\n' +
                            '                    </td>\n' +
                            '                    <td class="lssghj{#id}">\n' +
                            '                         <div >\n' +
                            '                        原零售: <input type="text" class="form-control" value="'+data[i].lingshou_price+'" name="yls{#id}" id="yls{#id}" style="width: 60px;"> 元 / '+data[i].unit+
                            '                        </div>   \n' +
                            '                         <div >\n' +
                            '                        活动期: <input type="text" class="form-control huodong" value="'+data[i].huodong_price+'"  name="hdls{#id}" id="hdls{#id}" style="width: 60px;"> 元 / '+data[i].box_num+data[i].unit+
                            '                        </div>   \n' +
                            '                    </td>\n' +
                            '                    <td>\n' +
                            '                        <input type="text" class="form-control" value="'+data[i].cp_sm+'" name="proTableInputSm4{#id}" id="proTableInputSm4{#id}"  placeholder="简要说明产品">\n' +
                            '                    </td>\n' +
                            '                    <td>\n' +
                            '                     <a class="btn btn-white btn-bitbucket">\n' +
                            '                            <i class="fa fa-trash-o"></i> 删除\n' +
                            '                        </a>\n' +
                            '                    </td>\n' +
                            '                </tr>';

                        var cpxq5 = changpingxianqin8;
                        uploadTr(cpxq5,'#Cpxq44','',g4,'',i);
                    }else if(data[i]['fylx']==7) {
                        console.log(data,'data222')

                        var changpingxianqin7 = '<tr class="text-center">\n' +
                            '                    <td id="proTableInput4{#id}">\n' +
                            '                    </td>\n' +
                            '\n' +
                            '                    <td class="lssghj{#id}">\n' +
                            '                        <input type="text" class="form-control" name="lssghj{#id}" id="lssghj{#id}" value="'+data[i].wangdian_price+'" placeholder=""> 元 / 桶\n' +
                            '                    </td>\n' +
                            '                    <td class="mclsj{#id}">\n' +
                            '                        <input type="text" class="form-control" name="mclsj{#id}" id="mclsj{#id}" value="'+data[i].lingshou_price+'" placeholder=""> 元 / 桶\n' +
                            '                    </td>\n' +
                            '                    <td>\n' +
                            '                        <input type="text" class="form-control" name="proTableInputSm4{#id}" id="proTableInputSm4{#id}" value="'+data[i].cp_sm+'" placeholder="简要说明产品">\n' +
                            '                    </td>\n' +
                            '                    <td>\n' +
                            '                     <a class="btn btn-white btn-bitbucket">\n' +
                            '                            <i class="fa fa-trash-o"></i> 删除\n' +
                            '                        </a>\n' +
                            '                    </td>\n' +
                            '                </tr>';
                        var cpxq5 = changpingxianqin7;

                        uploadTr(cpxq5,'#Cpxq43','',g3,'',i);

                         //uploadTr(cpxq5,'#Cpxq4','',g,'',i);

                    }else {

                        var cpxq5 = '<tr class="text-center">\n' +
                            '                <td id="proTableInput4{#id}">\n' +
                            '\n' +
                            '                </td>\n' +
                            '\n' +
                           /* '                <td>\n' +
                            '                    <div class="input-group">\n' +
                            '                        <input type="text" class="form-control" name="proTableInputBl4{#id}" value="'+data[i]['cp_zb']+'" id="proTableInputBl4{#id}" aria-label="" style="width: 60px;height: 30px">\n' +
                            '                        <span class="input-group-addon">%</span>\n' +
                            '                    </div>\n' +
                            '                </td>\n' +*/
                            '                <td>\n' +
                            '                    <input type="text" class="form-control" name="proTableInputSm4{#id}" value="'+data[i]['cp_sm']+'" id="proTableInputSm4{#id}" placeholder="简要说明产品">\n' +
                            '                </td>\n' +
                            '                <td>\n' +
                            '                    <a class="btn btn-white btn-bitbucket">\n' +
                            '                        <i class="fa fa-trash-o"></i> 删除\n' +
                            '                    </a>\n' +
                            '                </td>\n' +
                            '            </tr>';

                        uploadTr(cpxq5,'#Cpxq4','',g,'',i);

                    }




                }



                if(fylx==2){
                    for(var i=0;i<data.length;i++){

                        $("#Cpxq42>tr").each(function(){
                            $(this).find(".input-group ").eq(0).closest('.input-group').hide();
                        })

                        $("#Cpxq42").find(".inin ").eq(i).html(data[i]['name']);

                        $("#Cpxq42").find(".selectedOnlyOne ").eq(i).css("display", "inline");
                        var Td = $("#Cpxq42").find('tr').eq(i).find('td').eq(0).attr("ID");
                        var cp_id=data[i]['id'];

                        $("#Cpxq42").find('input[name="' +Td +'"]').val(cp_id);

                    }
                    break;
                }else if(fylx==4){
                    for(var i=0;i<data.length;i++){

                        $("#Cpxq44>tr").each(function(){
                            $(this).find(".input-group ").eq(0).closest('.input-group').hide();
                        })

                        $("#Cpxq44").find(".inin ").eq(i).html(data[i]['name']);

                        $("#Cpxq44").find(".selectedOnlyOne ").eq(i).css("display", "inline");
                        var Td = $("#Cpxq44").find('tr').eq(i).find('td').eq(0).attr("ID");
                        var cp_id=data[i]['id'];

                        $("#Cpxq44").find('input[name="' +Td +'"]').val(cp_id);

                    }
                    break;
                }else if(fylx==5){

                }else if(fylx==7){
                    for(var i=0;i<data.length;i++){

                        $("#Cpxq43>tr").each(function(){
                            $(this).find(".input-group ").eq(0).closest('.input-group').hide();
                        })

                        $("#Cpxq43").find(".inin ").eq(i).html(data[i]['name']);

                        $("#Cpxq43").find(".selectedOnlyOne ").eq(i).css("display", "inline");
                        var Td = $("#Cpxq43").find('tr').eq(i).find('td').eq(0).attr("ID");
                        var cp_id=data[i]['id'];

                        $("#Cpxq43").find('input[name="' +Td +'"]').val(cp_id);

                    }
                    break; //Cpxq44

                }else {
                    for(var i=0;i<data.length;i++){

                        $("#Cpxq4>tr").each(function(){
                            $(this).find(".input-group ").eq(0).closest('.input-group').hide();
                        })

                        $("#Cpxq4").find(".inin ").eq(i).html(data[i]['name']);

                        $("#Cpxq4").find(".selectedOnlyOne ").eq(i).css("display", "inline");
                        var Td = $("#Cpxq4").find('tr').eq(i).find('td').eq(0).attr("ID");
                        var cp_id=data[i]['id'];

                        $("#Cpxq4").find('input[name="' +Td +'"]').val(cp_id);

                    }
                }



        }


        var fylx ="{$fylx}";
        //console.log(fylx,'fylx')
        if(fylx==2){
            var fylxnum=$('#fylx').val();
            $('#fylx').val('2');
            //选定经销商
            $(".khjinxiaoshnag").parent('label').siblings('label').removeClass('active')
            $(".khjinxiaoshnag").parent('label').addClass('active')
            $("#angencyTable").show();
            $("#sysTable").hide();
            $("#netTable").hide();
            $(".netlist").remove();
            $("#JinXiaoShangZhu").empty();
            $("#khxqtype").val('1');
            $(".khxitong").attr('disabled',true);
            $(".khwangdian").attr('disabled',true);

            //选择单品  cpxqdp
            $(".cpxqdp").parent('label').siblings('label').removeClass('active')
            $(".cpxqdp").parent('label').siblings('label').find('input').attr('disabled',true);
            $(".cpxqdp").parent('label').addClass('active')
            $(".cpxqdp").attr('disabled',true);//当前单品也不许点击
            //showTable($(this),42);
            $("#Cpxq0").empty();
            $("#Cpxq1").empty();
            $("#Cpxq2").empty();
            $("#Cpxq3").empty();
            //$("#Cpxq4").empty();

//            if(fylxnum!=7){
//                addHang72();
//            }
            $("#cpxqtype").val('5');


        }else if(fylx==4){
            var fylxnum=$('#fylx').val();
            $('#fylx').val('2');
            //选定经销商
            $(".khjinxiaoshnag").parent('label').siblings('label').removeClass('active')
            $(".khjinxiaoshnag").parent('label').addClass('active')
            $("#angencyTable").show();
            $("#sysTable").hide();
            $("#netTable").hide();
            $(".netlist").remove();
            $("#JinXiaoShangZhu").empty();
            $("#khxqtype").val('1');
            $(".khxitong").attr('disabled',true);
            $(".khwangdian").attr('disabled',true);

            //选择单品  cpxqdp
            $(".cpxqdp").parent('label').siblings('label').removeClass('active')
            $(".cpxqdp").parent('label').siblings('label').find('input').attr('disabled',true);
            $(".cpxqdp").parent('label').addClass('active')
            $(".cpxqdp").attr('disabled',true);//当前单品也不许点击
            //showTable($(this),42);
            $("#Cpxq0").empty();
            $("#Cpxq1").empty();
            $("#Cpxq2").empty();
            $("#Cpxq3").empty();
            //$("#Cpxq4").empty();

//            if(fylxnum!=7){
//                addHang72();
//            }
            $("#cpxqtype").val('5');
        }

        //这里不错


    })

    /*$(document).ready(function () {
        //费用详情
        //var fee="{$fee}";
        var data = JSON.parse('{$fee}');
        for(var i=0;i<data.length;i++){
            $("#FeiYongLeiXingList>tr").each(function(){
                $(this).find(".input-group ").eq(0).closest('.input-group').hide();
            })
            $("#FeiYongLeiXingList").find(".inin ").eq(i).html(data[i]['title']);
            $("#FeiYongLeiXingList").find(".selectedOnlyOne ").eq(i).css("display", "inline");
            var Td = $("#FeiYongLeiXingList").find('tr').eq(i).find('td').eq(0).attr("ID");
            var cp_id=data[i]['feetype'];
            $("#FeiYongLeiXingList").find('input[name="' +Td +'"]').val(cp_id);
            Td=Td.replace("feetype", "state");
            var opts = document.getElementById(Td);
            console.log(getHsonLength(opts.children))
            console.log('tttttttt')
            console.log(opts.children);
            var value = data[i]['paymethod'];
            if(value!=""){
                var leng =opts.options.length;
                console.log(leng,123);
                for(var k=0;k<3;k++){
                    if(value==opts.options[k].value){
                        console.log(k);
                        opts.options[i].selected = 'selected';
                        alert(opts.options[i].value);
                        break;
                    }
                }
            }
        }
    })*/

    function ZheJiaLv_change(idnum){
        //console.log(idnum,'idnum')
        var id='dealerZheJiaLv'+idnum;         //折价率id
        //console.log(id,'id')
        var ZheJiaLv = $('#'+id).val(); //折价率
        var xjid = id.replace("dealerZheJiaLv", "nowprice"); //现价id
        var yjid = id.replace("dealerZheJiaLv", "oldprice"); //原价id
        var oldprice = $('#'+yjid).val();  //原价

        var wd=id.replace("dealerZheJiaLv", "nowprice2"); //网点现供价id
        var wdxgj = $('#'+wd).val();  //网点现供价

        //console.log(ZheJiaLv,'ZheJiaLv')
        if(ZheJiaLv>=0){
            var xj =oldprice*(100-ZheJiaLv)/100; //现价
            var sj='';
            var dk='';
            if(xj>0){
                sj=parseFloat(100*(wdxgj-xj)/xj).toFixed(2);
            }else {
                sj='';
            }
            if(wdxgj>0){
                dk=parseFloat(100*(xj-wdxgj)/wdxgj).toFixed(2);
            }else {
                dk='';
            }

            $('#'+xjid).val(xj);
            //console.log(xjid,'xjid')
            var str='<span>'+'                            顺加'+sj+'% 倒扣'+dk+'</span>'+'%\n' +
                '<a class="hover" href="#">\n' +
                '                                <span>帮助</span>\n' +
                '                                <div class="ex" style="width: 400px;height: 100px;">经销商的顺加毛利率 =（网点现供价 - 经销商现供价）/ 经销商现供价\n' +
                '                                    <br>\n' +
                '                                    经销商的倒扣毛利率 = （网点现供价 - 经销商现供价）/ 网点现供价</div>\n' +
                '                            </a>';

            var  jj=$('#'+id).parent().next().next().html();//这个是对的
            $('#'+id).parent().next().next().html(str);
        }else {
            $('#'+xjid).val(oldprice);
            $('#'+id).val('0');
        }
    }

    function wuliao2(id) {
        console.log(id,'wuliao')
        entranceX2x('wlName'+id,
            "{:url('select/materialjson')}?id="+1+'&num='+id,
            '',function (data,id) {
                console.log(id,'wuliaoid')
                $(this).val(data.id);
                $(this).closest('.input-group').hide();
                $(this).closest('.input-group').hide();
                $('#select'+id).show().find('.inin').html(data.key);
                var s = "The rain in Spain falls mainly in the plain.";
                var ids = id.substring(1, 20);  // substring
                var rs = $('#thisWL'+ids).attr('rs');
                rs = JSON.parse(rs);
                for(var i=0;i<rs.length;i++){
                    if(rs[i].id==data.id){
                        $('#unit'+id).html(rs[i].unit)
                        $('#factory'+id).html(rs[i].factory)
                        var wlnum = $('#wlnum'+id).val();
                        var allmoney=wlnum*rs[i].factory;
                        $('#allmoney'+id).html(allmoney)
                    }
                }
            }
        );
    }

    function wuliao(id) {
        entranceX2x('wlName'+id,
            "{:url('select/materialjson')}?id="+1,
            '',function (data) {
                $(this).val(data.id);
                $(this).closest('.input-group').hide();
                $(this).closest('.input-group').hide();
                $('#select'+id).show().find('.inin').html(data.key);



                var src="images/off_1.png";
                     alert(src.substring(7,10));

                console.log(id,'id')
                var iddd=id.toString();
                var ids = iddd.substring(1, id.length);

                var rs = $('#thisWL'+ids).attr('rs2');
                console.log(ids,'ids')
                console.log(id,'id')
                console.log(rs)
                rs = JSON.parse(rs);


                /*console.log(data.id,'data.id')
                console.log(rs,'rs')*/
                for(var i=0;i<rs.length;i++){
                    if(rs[i].id==data.id){
                        console.log(data.id,'data.id')
                        console.log(rs[i],'rs[i]')
                        console.log(id,'id')
                        $('#unit'+ids).html(rs[i].unit)
                        $('#factory'+ids).html(rs[i].factory)
                        var wlnum = $('#wlnum'+ids).val();
                        var allmoney=wlnum*rs[i].factory;
                        $('#allmoney'+ids).html(allmoney)

                        $('#allmoneys'+ids).val(allmoney)
                    }
                }
            },2
        );
    }

    function yangpin(id) {
        console.log(id,'yangpin')
        entranceX2x('wlName'+id,
            "{:url('select/materialjson')}?id="+0,
            '',function (data) {
                console.log(id,'yangpinid')
                $(this).val(data.id);
                $(this).closest('.input-group').hide();
                $(this).closest('.input-group').hide();
                $('#select'+id).show().find('.inin').html(data.key);
                var rs = $('#thisWL'+id).attr('rs2');
                rs = JSON.parse(rs);
                for(var i=0;i<rs.length;i++){
                    if(rs[i].id==data.id){
                        $('#unit'+id).html(rs[i].unit)
                        $('#factory'+id).html(rs[i].factory)
                        var wlnum = $('#wlnum'+id).val();
                        var allmoney=wlnum*rs[i].factory;
                        $('#allmoney'+id).html(allmoney)
                        $('#allmoneys'+id).val(allmoney)
                    }
                }
            },2
        );
    }

    function ZheJiaLv_change2(idnum){

        var id='dealerZheJiaLv2'+idnum;         //折价率id
        console.log(id,'id')
        var ZheJiaLv = $('#'+id).val(); //折价率
        var xjid = id.replace("dealerZheJiaLv2", "nowprice2"); //现价id
        var yjid = id.replace("dealerZheJiaLv2", "oldprice2"); //原价id
        var oldprice = $('#'+yjid).val();  //原价
        console.log(ZheJiaLv,'ZheJiaLv')
        if(ZheJiaLv>=0){
            var xj =oldprice*(100-ZheJiaLv)/100;
            $('#'+xjid).val(xj);

        }else {
            $('#'+xjid).val(oldprice);
            $('#'+id).val('0');
        }
    }

    function nowprice_change(idnum){

        var id='nowprice'+idnum;
        console.log(id,'id')
        var nowprice = $('#'+id).val();
        var zkid = id.replace("nowprice", "dealerZheJiaLv"); //折扣id
        var yjid = id.replace("nowprice", "oldprice"); //原价id
        var oldprice = $('#'+yjid).val();
        console.log(oldprice,'oldprice')
        console.log(nowprice,'nowprice')

        var wd=id.replace("nowprice", "nowprice2"); //网点现供价id
        var wdxgj = $('#'+wd).val();  //网点现供价

        if(nowprice>=0){
            var zjl =parseFloat(100-(100*nowprice/oldprice).toFixed(2));//折价率

            var sj='';//顺加
            var dk=''; //倒扣
            if(nowprice>0){
                //sj=100*(wdxgj-nowprice)/nowprice;
                sj=parseFloat(100*(wdxgj-nowprice)/nowprice).toFixed(2);
            }else {
                sj='';
            }
            if(wdxgj>0){
                //dk=100*(nowprice-wdxgj)/wdxgj;

                dk=parseFloat(100*(nowprice-wdxgj)/wdxgj).toFixed(2);
            }else {
                dk='';
            }

            console.log(sj,'sj')
            console.log(dk,'dk')
            /*var sjv=sj.toFixed(2);
            var dkv=dk.toFixed(2);*/

            var str='                            顺加'+sj+'% 倒扣'+dk+'%\n' +
                '<a class="hover" href="#">\n' +
                '                                <span>帮助</span>\n' +
                '                                <div class="ex" style="width: 400px;height: 100px;">经销商的顺加毛利率 =（网点现供价 - 经销商现供价）/ 经销商现供价\n' +
                '                                    <br>\n' +
                '                                    经销商的倒扣毛利率 = （网点现供价 - 经销商现供价）/ 网点现供价</div>\n' +
                '                            </a>';


            var  jj=$('#'+id).parent().next().next().html();//这个是对的
            $('#'+id).parent().next().next().next().next().html(str);

            $('#'+zkid).val(zjl);
            $('#'+id).val();
        }else {
            $('#'+id).val(oldprice);
            $('#'+zkid).val('0');
        }
    }

    function nowprice_change2(idnum){
        var id='nowprice2'+idnum;
        var nowprice = $('#'+id).val();
        var zkid='dealerZheJiaLv2'+idnum;
        var yjid='oldprice2'+idnum;
        var oldprice = $('#'+yjid).val();
        if(nowprice>=0){
            var zjl =parseFloat(100-(100*nowprice/oldprice).toFixed(2));
            $('#'+zkid).val(zjl);
            $('#'+id).val();
        }else {
            $('#'+id).val(oldprice);
            $('#'+zkid).val('0');
        }
    }
















    $(function () {
        //点击物料样品单选
        $('body').on('click','.wy',function () {
            var val=$(this).val();
            var kk=$(this).parents('td');
            kk.closest('td').find('.inin').html('')
            kk.closest('td').find('[name=product]').val('')
            kk.closest('td').find('.selectedOnlyOne').hide()
            kk.find('.inin').html('')
            kk.find('[name=product]').val('')
            kk.find('.selectedOnlyOne').hide()
            var numid =$(this).attr("data-id")
            var wyval=$(this).val();
            if($(this).val()==1){  //为什么进不去这里
                $("#ypwlType"+numid).val('0');
                var class1 = kk.find('#wlName'+numid).attr('class');
                var ids='#wlName'+numid;
                kk.find('#wlName'+numid).show()
                kk.find('#wlName2'+numid).hide()
            }else{
                $("#ypwlType"+numid).val('1');
                kk.find('#wlName'+numid).hide()
                kk.find('#wlName2'+numid).show()
                var ids='#wlName2'+numid;
                var class1 = kk.find('#wlName2'+numid).attr('class');
                /*kk.find('#select2wlName'+numid).hide()
                kk.find('#select2wlName2'+numid).show()*/
            }
        })
    })

    $(document).ready(function () {
        //样品搜索补全
        $(".sample").bsSuggest({
            url: "{:url('select/samplejson')}",
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onSetSelectValue', function (e, keyword, data) {
            console.log('yp')
            $(this).closest('.input-group').hide()
            $(this).val('')
            $(this).closest('td').find('.inin').html(keyword.key)
            $(this).closest('td').find('[name=product]').val(keyword.id)
            $(this).closest('td').find('.selectedOnlyOne').show()

        })


        //物料搜索补全
        $(".material").bsSuggest({
            url: "{:url('select/materialjson')}",
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            $(this).closest('tr').data('rs',JSON.stringify(result.value))
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            console.log('wl')
            $(this).closest('.input-group').hide()
            $(this).val('')
            $(this).closest('td').find('.inin').html(keyword.key)
            $(this).closest('td').find('[name=product]').val(keyword.id)
            $(this).closest('td').find('.selectedOnlyOne').show()

            var rs = $(this).closest('tr').data('rs')
            rs = JSON.parse(rs)
            for(var i=0;i<rs.length;i++){
                if(rs[i].id==keyword.id){
                    $(this).closest('tr').find('.unit').html(rs[i].unit)
                    $(this).closest('tr').find('.price').html(rs[i].factory)
                }
            }
        })

    })

    function num_to(num){

        var xtnumid = 'JinXiaoShangNum'+num;
        var rs = $('#'+xtnumid).attr('rs');
        var xtnum = $('#'+xtnumid).val();
        if(rs!=''){
            if(xtnum>rs){
                var xtnameid = 'selectJinXiaoShang'+num;
                var xtname = $('#'+xtnameid).find('.inin').html();

                alert(xtname+'网点数最多为'+rs);
                var xtnum = $('#'+xtnumid).val(rs);
            }else if(!(xtnum>0)){
                var xtnum = $('#'+xtnumid).val(0);
            }

        }


    }







</script>
</body>

</html>